UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithImage:#"rGoBack"
style:UIBarButtonItemStylePlain
target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
I use this source. but It doesn't work. I don't know why not. please..
From the first glance:
initWithImage:#"rGoBack"
here UIImage parameter required and NSString is passed instead. Try writing something like:
initWithImage:[UIImage imageNamed:#"rGoBack.png"]; // or whatever image name you have
Related
i have problem that i have 3 views,
i goto first view to 2nd and want to change mine back button title
i write this code in viewDidLoad of 2nd View but its not working :(
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
go to 1st view controller and add the following code before you push the viewController,
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Inv Menu" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
I change the UIBarButtonItem title at run time but it does not work
if(self.toolbarItems!=nil)
{
NSArray *toolbaritem=self.toolbarItems;
UIBarButtonItem* tmpeditButton =[toolbaritem objectAtIndex:0];
tmpeditButton.title=#"Done";
NSLog(#"log %#",tmpeditButton.title);
}
Log is always displays the value of NULL. Why and how to fix that?
Use this
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:nil];
I want set my custom method "Home" with RightNavagation button how should I?
My code
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:#selector(home:)];
[barButton setImage:[UIImage imageNamed:#"home_btn.png"]];
[self.navigationItem setRightBarButtonItem:barButton];
Know I want to link this method with it.
-(IBAction)home{
MainViewController *main=[[MainViewController alloc]
initWithNibName:#"MainViewController" bundle:nil];
[self.navigationController pushViewController:main animated:YES];
}
how should I Do this please help me out.
Try to change
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:#selector(home:)];
in
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:#selector(home)];
compare your selector #selector(home:) with your action -(IBAction)home
See the missing colon in your action?
Change your action to
- (IBAction)home:(id)sender
How would I be able to set the position of a UIBarButtonItem? Like, I would like to set it to be on either the very right of a UIToolbar or the very left depending on a state.
Thank you.
You do not set directly the position of a UIBarButtonItem in an UIToolbar. Instead you defined the items' order and put flexible space on the left or on the right.
What you can do is:
Create the UIBarButtonItem you want to place (button 1).
Create an UIBarButtonItem of type UIBarButtonSystemItemFlexibleSpace (button 2).
If you want to put the button on the left, create an array with (button 1) and (button 2) and pass it to the UIToolbar by using the setItems:animated: method.
If you want to put the button on the right, create an array with (button 2) and (button 1) and pass it to the UIToolbar by using the setItems:animated: method.
I hope it helps you...
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* PrevButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 target:nil action:nil]; //<
UIBarButtonItem* NextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:nil action:nil]; //>
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(doneClicked:)];
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *fake = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil] ;
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects: PrevButton,fake, NextButton,fake,flexSpace,fake,doneButton,nil] animated:YES];
Link explains Bar Button Item Methods and Arguments
https://developer.apple.com/library..... Use Fake Item to get exact pinch location on Button...
Does anyone know how to use an icon instead of text for the UINavigationController back button?
alt text http://www.img-hosting.de/bilder/24505iPhoneSimulator2png
Try this:
UIBarItem *backBar = [[UIBarButtonItem alloc] initWithImage:yourImage style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = backBar;
[backBar release];
you can also use initWithCustomView if you need something more elaborate