Removing the text from the automated back button on a navigation controller - xcode

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 = #"";

Related

change left navigation button text

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!

XCODE : Changing which view controller BACK button segues to

Is there a way to change the "parent" of a view controller so you can specify which view controller the back button will segue to without creating a custom back button?
Or is the only way to create a custom back button with a custom action?
If you have access to the navigation controller, you could manually insert a view controller in to its stack of view controllers [self.navigationController setViewControllers:] before the current view controller. That would allow the navigation controller to perform its regular actions yet still navigate back to your desired view controller.
Try To create a custom button like
UIBarButtonItem * buttonBack = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Back" ofType:#"png"]] style:UIBarButtonItemStylePlain target:self action:#selector(onBackClick:)];
[self.navigationItem setLeftBarButtonItems:#[buttonBack] animated:YES];
and make a method..
- (IBAction)onBackClick:(id)sender
{
// your code
// Write your code what you want to do...
}

xcode - switch between more than 2 view controllers

I have several .xib files (page1, page2 ...) and want to switch between them using buttons (as a navigation bar)
I am using
page1 *second = [[page1 alloc] initWithNibName:nil bundle:nil];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:second animated: YES];
page2 *second = [[page2 alloc] initWithNibName:nil bundle:nil];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:second animated: YES];
and so on...
I learned that this consumes a lot of memory because I am presenting a view over and over again and after switching back and forth the app sometimes crashes.
So, question is what can I do?
I tried this:
[self dismissModalViewControllerAnimated:YES]
but after dismiss it returns to the previous page and I can not navigate to another one.
Probably I used a stupid approach, however, I've done a few apps that way and don't want to change the controller completely.
Thank you for your help!
I think you have to create IBActions from that 2 blocks of code an link that IBActions to the right button.

UIBarButtonItem in storyboards

the master detail application included when you use Storyboards this code in view did load.
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
i want to use this like in same project with .xib'S
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(showGegenstellenView)];
the problem is that i can't implement this code in the storyboard project. I can't find help special for storyboards...
-(void)showGegenstellenView{
GegenstellenViewController *gegenstellenViewController = [[GegenstellenViewController alloc]initWithMasterController:self Gegenstellen:nil];
[self presentModalViewController:gegenstellenViewController animated:YES];
}
Finally I want to click in the table view the add button and a view comes with a formular.
All this works in the project with xib's i have. But i want it with storyboards! I have no problem when u want see the xib project via team viewer or as sib by mail.
Best Regards
John

dismiss UIPopoverController (if visible) after tapping a UIBarButtonItem

I'm trying to dismiss any currently visible UIPopoverControllers if/when another UIBarButtonItem is tapped as seen on Pages for the iPad when tapping between Styles/Media/Tools etc.
I've done this, but it's too specific. Looking for something generic.
if ([popoverController isPopoverVisisble]) {
[popoverController dismissPopoverAnimated:YES];
}
Thanks!
Did you set the passthroughViews property of the popover controller? If you do this, then taps outside the popover will not cause the popover to automatically dismiss, but will instead be sent to the views in that array. You should be able to add the UIBarButtonItem to this array, and then dismiss the popover in that handler.
randallmeadows answer will NOT work. UIBarButtonItem is not descendant of UIView, which means you cannot add it to passthroughViews.
The only solution I found for now is to create UIBarButtonItem with custom UIButton using
UIBarButtonItem *b = [[UIBarButtonItem alloc] initWithCustomView:button]
and then
popoverController.passthroughViews = [NSArray arrayWithObject:b.customView];
But be prepared that you'll loose all the styling - you cannot create UIButton that looks like UIBarButtoItem too easily.
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.passthroughViews = #[];
Works for me

Resources