set the back button from the pushViewController view - ios

I have a viewController A, is it possible that I pre-set the back button of viewController B when it is pushed to.
Controller *B = [Controller viewControllerFromStoryboardWithProfile: profile editMode: NO];
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:#"Home"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[B.navigationItem setBackBarButtonItem:newBackButton];
[self.navigationController pushViewController:B animated:YES];
Something like this?

Try this code:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Home"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[self.navigationController pushViewController:anotherViewController];
source: How to create backBarButtomItem with custom view for a UINavigationController

Related

UIToolBar is black for a split second on load

Every time I load up the UIView that holds the UIToolbar below (which is attached to the keyboard), it turns black for a second until the view fully loads, and then turns back to the standard white color. I'm stumped as to why this keeps happening.
Here's how I'm forming the UIToolbar:
[self.answerField becomeFirstResponder];
UIToolbar *toolbar = [UIToolbar new];
UIBarButtonItem *sectionButton = [[UIBarButtonItem alloc] initWithTitle:#"§" style:UIBarButtonItemStylePlain target:nil
action:#selector(addSectionSymbol:)];
UIBarButtonItem *paraButton = [[UIBarButtonItem alloc] initWithTitle:#"¶" style:UIBarButtonItemStylePlain target:nil
action:#selector(addParaSymbol:)];
UIBarButtonItem *flexSpacing = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSString *infoLabel = #"Select text to italicize. Always use italics.";
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:infoLabel style:UIBarButtonItemStylePlain target:nil action:nil];
[infoButton setEnabled:NO];
[toolbar setItems:[NSArray arrayWithObjects:sectionButton, paraButton, flexSpacing, infoButton, nil]];
self.answerField.inputAccessoryView = toolbar;
[toolbar sizeToFit];
Any ideas?

Add Back Button back into navigationController after adding custom button

I'm trying to implement a navigationcontroller that has a uitableview in it. This tableview should be editable, and to add rows to the table the user should press a plus button on the top bar on the screen. However, when I add a uibarbuttonitem and set it to the left side, the back button doesn't re-appear? how would i make it reappear?
The edit button:
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editButtonPressed)];
[[self navigationItem] setRightBarButtonItem:button];
The editButtonPressed method:
[_actionList setEditing:TRUE];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addAction)];
[[self navigationItem] setLeftBarButtonItem:addButton animated:TRUE];
editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(editButtonDone)];
[[self navigationItem] setRightBarButtonItem:editButton animated:TRUE];
[self disableButtons];
The editButtonDone method:
[_actionList setEditing:FALSE];
editButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editButtonPressed)];
[[self navigationItem] setRightBarButtonItem:editButton];
[self enableButtons];
I'm a beginner so sorry if this is dumb.
Try resetting left bar button when you leave edit mode.
[[self navigationItem] setLeftBarButtonItem:nil animated:YES];
try this:
[yourNavBar pushNavigationItem:self.navigationItem animated:NO];
Hope it helps

need to change the back button name on navigation bar in ipad

UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(pop)];
self.navigationItem.backBarButtonItem = barBtnItem;
I placed the above code in iphone it is working.when i am trying it for ipad it is not working.what may be reason?
Thanks in Advance
This changes NavigationBar's BackButton text, to do before pushing a new view controller :
UIViewController *myViewController = [[UIViewController alloc] init];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"My text" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[self.navigationController pushViewController:myViewController animated:YES];
And it works for both iPhone and iPad devices.
It looks like you linked your UINavigationController with Interface Builder, you should have a look at this :

Bar button not receiving touch

I have 2 bar buttons on the tool bar , one is not working and the other is working. Some times when we touch the tip of the first bar button it will work, I think this has to be a problem with flexible space between them.
I couldn't find any possible solution, any help will be appreciated!
I'm pasting the code below
editbutton is the first button and mybutton is the second button
-(void) rightButtonToolbar:(UIBarButtonItem*)menuButton{
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,TOOLBAR_WIDTH ,44)];
NSMutableArray *barButtons = [[NSMutableArray alloc]init];
UIBarButtonItem *flexiSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barButtons addObject:flexiSpace];
if (showEditButton)
{
NSLog(#"showeditbutton");
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editOffer)];
[barButtons addObject:editButton];
[editButton release];
}
UIBarButtonItem *myButton2 = [[UIBarButtonItem alloc] initWithTitle:#"Kopiren" style:UIBarButtonSystemItemAction target:self action:#selector(copyOffer)];
[barButtons addObject:myButton2];
if (menuButton != nil) {
menuButtonShown=YES;
[barButtons addObject:menuButton];
}
else {
menuButtonShown=NO;
}
[toolbar setItems:barButtons animated:YES];
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithCustomView:toolbar];
[self.navigationItem setRightBarButtonItem:rightBarButton animated:YES];
[barButtons release];
[flexiSpace release];
[rightBarButton release];
[toolbar release];
[myButton2 release];
}

Navigation Controller back button

How can I create a back button of a navigation controller programmatically?
In -(void)loadView or similar:
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:#"back" style:UIBarButtonItemStyleBordered target:self action:#selector(backPressed:)];
self.navigationItem.leftBarButtonItem = btn;
[btn release];
-(void)backPressed: (id)sender
{
[self.navigationController popViewControllerAnimated: YES]; // or popToRoot... if required.
}

Resources