need help to change the text for the left navigation button in ios8
tried
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"My Text" style:UIBarButtonItemStylePlain target:nil action:nil];
and
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"My Text" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
Please help
UIButton *buttonLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonLeft addTarget:self action:#selector(buttonLeftAction) forControlEvents:UIControlEventTouchUpInside];
[buttonLeft setFrame:CGRectMake(0, 0, 70, 20)];
[buttonLeft setTitle:#"YourTitle" forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:buttonLeft];
Try above code.
need help to change the text for the left navigation button
That's very confused, because the left navigation button and the back button are two completely different things. So you say "left navigation button" but then what you set is the back button. Thus it's impossible to be sure what you're really trying to do. And moreover, the left button and the back button conflict with one another - by default, they will not both appear. So you have to be careful about that too.
I'm going to assume, in this answer, that although you say the left navigation button, you don't mean it - you mean the back button. And that the top view controller has no left button.
Assuming that's the case, the thing to keep in mind here is that when the back button is showing, it is not the current view controller's navigation item whose back button this is, but the view controller below it in the stack. That is, the back button belongs the back item's navigation item.
Thus, that is the view controller that needs to modify its navigation item's back item, and it needs to do it before another view controller gets pushed onto the stack - preferably much earlier, in its own viewDidLoad.
Thus, this code (from my book) will work if run in the viewDidLoad of the correct view controller:
UIBarButtonItem* b =
[[UIBarButtonItem alloc] initWithTitle:#"Go Back"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = b;
But of course if you mean the left bar button item after all, then forget all that. If you mean the left bar button item, then the problem is not that you've got the wrong view controller but that you've got the wrong bar button item!
Related
Maybe a silly question. But I've added a navigation item in code in my view controller:
//Set add transactions button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addButtonAction:)];
[self.navigationItem setRightBarButtonItem:addButton];
-(void)addButtonAction
{
}
And I want to segue from this navigation item directly to a new view controller. However I cannot create any segue from the previous view controller to the next one. And since my navigation item is created in code I cannot "pull" a segue from there to a new VC. How can I do that?
Do this
-(void)addButtonAction
{
MyNewViewController *myNewVC = [[MyNewViewController alloc] init];
// do any setup you need for myNewVC
//If you want to present modal
[self presentModalViewController:myNewVC animated:YES];
//If you want to push
[self.navigationController pushViewController:myNewVC animated:YES];
}
Add button to dismiss if presented using modal. In case of push it will have back button
How to change image by click on that image in Iphone.Instead of button click I want to click on image.Which method can I use UIImageView.
Use a button and make your picture the picture for the button. You can do all this in Storyboard and then right click the button and drag to the view you want to go to. It should work just like that.
After you drag the button to the storyboard go to the property inspector. Make the button a custom button in the drop down list and then use the image field to select your image. You will need to size the button correctly and set the fill property to "size to fit." the other button behaviors are all customizable if you don't want normal button behavior, i.e. visually reacting to a touch.
This can be done by using touchevents also
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([[touches anyObject] view] == self.m_ImageViewObjectName) {
//Here you can change the image of UIImageView
}
}
You have to set tapRecognizer for your ImageView. It'll detect tap on your ImageView and call the method -clickEventOnImage.
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(clickEventOnImage:)];
[tapRecognizer setNumberOfTouchesRequired:1];
[tapRecognizer setDelegate:self];
//Don't forget to set the userInteractionEnabled to YES, by default It's NO.
myImageView.userInteractionEnabled = YES;
[myImageView addGestureRecognizer:tapRecognizer];
Add your clickEventOnImage: will look like this :
-(void) clickEventOnImage:(id) sender
{
[myImageView setImage:[UIImage imageNamed: #"myNewImageName.png"]];
}
I'm sure this was covered before but I can't find exactly what I'm after. I'm using a custom image for the back button on my navigation controller and need to remove the text, is there a simple way of doing this? Thanks.
Try to set the back button as follows:
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"back-arrow.png"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(backButtonPressed:)];
self.navigationItem.leftBarButtonItem.title = #"";
i am making a customized back button which works exactly as a real back button does. below is my code
UIButton *cusBack = [UIButton buttonWithType:101];
[cusBack setTitle:#"Back" forState:UIControlStateNormal];
[cusBack addTarget:self action:#selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
self.view addSubView:cusBack;
and here is my selector:
-(void)clickBack{
PrevPage *pPage = [[PrevPage alloc] init];
[self.navigationController pushViewController:pPage animated:YES];
[pPage release];
}
actually, it works but the direction it creates is from RIGHT to LEFT. but I want the page to move from LEFT to RIGHT since it goes back to the recent page
thank you!
If you want to have the same behavior as the back button you should try another approach:
-(void)clickBack{ //Your presenting view controller will always be the last view controller on the stack.
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1] animated:YES];
}
Also, if you need to do some changes to the previous view controller, all you need to do is import it's header file and then you can use it's properties and public methods before popping the view controller.
#import "MyPreviousViewController.h"
...
-(void)clickBack{
[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1].title = #"Change title for previous view controller";
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1] animated:YES];
}
Currently, your back button doesn't work as the real back button does, because, instead of popping the last view controller off the stack(also releasing the objects), you actually keep pushing new view controllers on the stack. You might have some issues if this stack gets too big.
I have a PopoverController view that allows a user to download a file. On button press, the popOver view will expand in size, display download status, and the main view controller will be obscured by an unhidden "cover" view that has been added to the PopoverController's "passThroughViews" property so that the user can not accidentally dismiss the pop over while the file is downloading.
My problem is that, in storyboards, my main viewController is embedded in a Navigation Controller. I can't seem to cover the navigation controller's bar with a view in the storyboard, and if the user presses anywhere on the navigation bar then the popover will disappear and the user will lose the download's progress bar.
How do I either cover up the navigation bar with my "cover" view, or how do I add the navigation bar's view to my popOverController's passThroughViews?
Opening the Popover from the main viewController:
- (IBAction)openDataOptionsPopOver:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
PopOverViewController *optionsWindow = [storyboard instantiateViewControllerWithIdentifier:#"dataOptions"];
self.popUp = [[UIPopoverController alloc] initWithContentViewController:optionsWindow];
[self.popUp setDelegate:self];
[nextNavButton setEnabled:NO]; //Disabling barButtonItem on the navigationController
optionsWindow.containerPopOver = self.popUp; //Pointer to the popover, to resize it later.
optionsWindow.coverView = self.coverView; //Pointer to the coverView, to (un)hide later
[popUp presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
Setting the passThroughViews property inside of the PopoverViewController:
//Expands the popOver on press of "refreshFileButton" to display progressView
-(void) explodeWindow
{
//setting self.navigationController.view and ...visibleViewController.view here didn't seem to work ...
[containerPopOver setPassthroughViews:[NSArray arrayWithObjects:coverView, nil]];
[containerPopOver setPopoverContentSize:CGSizeMake(600, 400) animated:YES];
[titleBarItem setTitle:#"Downloading File. Please Wait ..."];
[refreshFileButton setHidden:YES];
[progressView setHidden:NO];
[downloadLabel setHidden:NO];
[coverView setHidden:NO];
[progressView setProgress:0.0 animated:NO];
}
I've tried adding self.navigationController.view to passThroughViews with no success--it actually turns out to be a null pointer. And I can't seem to place a UIView at any level in storyboards that will cover all my controls without obscuring the popOver. What am I missing here? And thanks for reading.
Edit:
As Aglaia points out below out, implementing the following, and avoiding passThroughViews, is probably the best way to do this.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
//Don't dismiss our popover when the view covering our controls is present
if([coverView isHidden]){
return YES;
}else{
return NO;
}
}
Maybe there is something I am missing, but why don′t you just implement a new view controller with its navigation bar set to none and present it modally on button press? Then when the download is finished you just dismiss the view controller.
If you want the user to see the underlying view you can use a UIAlertView instead.
Alternatively set you view controller as the delegate of the popover controller and forbid the user to dismiss your popover on touch outside through
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Then when you want to dismiss it call dismissPopoverAnimated:
to cover the whole screen including navigation bar:
[myView setFrame:[[UIScreen mainScreen] bounds];
[self.navigationController.view addSubview:myView];