I have UINavigationController. Then i need to display navigationbar button. I used following code:
UINavigationController *nav=[[UINavigationController alloc] init];
[self.view addSubview:nav.view];
UIImage *info_iphone=[UIImage imageNamed:#"button.png"];
UIButton *infobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 48, 30)];
[infobtn setBackgroundImage:info_iphone forState:UIControlStateNormal];
[infobtn addTarget:self action:#selector(show_info:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:infobtn];
Sample Code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.viewController = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
In YourViewController's -viewWillAppear :
UIImage *info_iphone=[UIImage imageNamed:#"button.png"];
UIButton *infobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 48, 30)];
[infobtn setBackgroundImage:info_iphone forState:UIControlStateNormal];
[infobtn addTarget:self action:#selector(show_info:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:infobtn];
self.navigationItem.rightBarButtonItem = rightButton;
I think that the problem here is with the navigation controller. You can't add it as a subview of the UIViewControllers view. I am using story boards and there you can embed your View Controllers with Navigation Controllers.
Here, your "nav" does not know that it should care about your navigationItem. Your view controller is not in his viewControllers list.
I don't think adding UINavigationController as subview will work for you.
Rather you can add UINavigationController as subview(or as rootviewcontroller) to UIWindow in your AppDelegate file in didFinishLaunchingWithOptions method as follow :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[SampleViewController alloc] initWithNibName:#"SampleViewController" bundle:nil] autorelease];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
Than in your SampleViewController's Viewdidload method add the BarButton as follow :
UIImage *info_iphone=[UIImage imageNamed:#"button.png"];
UIButton *infobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 48, 30)];
[infobtn setBackgroundImage:info_iphone forState:UIControlStateNormal];
[infobtn addTarget:self action:#selector(show_info:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc]initWithCustomView:infobtn]];
Hopefully this will help you.. :)
use this bellow code...
UIImage *info_iphone=[UIImage imageNamed:#"button.png"];
UIButton *infobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 48, 30)];
[infobtn setBackgroundImage:info_iphone forState:UIControlStateNormal];
[infobtn addTarget:self action:#selector(show_info:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:infobtn];
[infobtn release];
UPDATE :
use bellow code
UIBarButtonItem *btnSave = [[UIBarButtonItem alloc]init];
btnSave.target = self;
btnSave.action = #selector(btnSave_Clicked:);
btnSave.title = #"Save";
btnSave.style=UIBarButtonItemStyleDone;
self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnSave;
Related
I have tried to add a UIBarButtonItem to my UINavigation bar but I can't get it to show up:
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width,self.view.frame.size.height)];
[self.view addSubview:self.webView];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(#"Back", #"")
style:UIBarButtonItemStyleDone
target:self
action:#selector(remove:)];
[self.navigationItem setLeftBarButtonItem: backButton];
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
self.webView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:self.url];
[self.webView loadRequest:request];
}
- (void)remove:(id)sender
{
[self removeFromParentViewController];
[self.webView stopLoading];
self.webView.delegate = nil;
}
I can't figure out why the button isn't there. Any help would be much appreciated!
Thanks.
Before add UIBarButtonItem to UINavigationBar, First change your UIWebView frame,
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width,self.view.frame.size.height - 50 )];
Here add (-50) to height of UIWebView.
And now, i just write code for how to add UIBarButtonItem to UINavigationBar:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:navBar];
UIBarButtonItem *Button = [[UIBarButtonItem alloc]
initWithTitle:#"MyButton"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(buttonAction)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"This is My Title "];
item.rightBarButtonItem = Button;
item.hidesBackButton = YES;
[navBar pushNavigationItem:item animated:NO];
Here is Method name is buttonActionthat execute/call when you tapped on UIBarButtonItem.
-(void)buttonAction
{
//stuff of code;
}
remove these two lines from your code and check it,
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
or you can add like this,
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"remove"
style:UIBarButtonItemStyleDone
target:self
action:#selector(remove:)];
UINavigationItem *item = [[UINavigationItem alloc]initWithTitle:#"remove"];
[item setLeftBarButtonItem:backButton];
[myBar setItems:[NSArray arrayWithObject:item]];
Richard, I understand what you want to achieve but I am not sure whether you are using a navigation controller already.
Case 1: using UINavigationController
If you are using Navigation Controller already then you don't need to add new Navigation bar.
If you are using NavigationController then show the use the bar from Navigation Controller and your code will work.
below two lines would not be required.
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
Case 2: Not using UINavigationController
If you are not using UINavigationController then you are required to add a Bar and add Bar button in the navigation item of Bar.
UINavigationBar *myBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"remove"
style:UIBarButtonItemStyleDone
target:self
action:#selector(remove:)];
UINavigationItem *item = [[UINavigationItem alloc]initWithTitle:#"remove"];
[item setLeftBarButtonItem:backButton];
[myBar setItems:[NSArray arrayWithObject:item]];
and you need to remove following line
[self.navigationItem setLeftBarButtonItem:backButton];
It will work perfectly. Let me know if you find any issues.
I am calling view controller method from delegate class, the method is called but uitableview declared in that method does not call it delegate methods and a buttons and view also alloc in that view but nothing is shown.
Explaining from begining:
On navigation controller needed a button and to be shown on all views. So, i took that in delegate this way.
UIButton *btnMenuOpen = [UIButton buttonWithType:UIButtonTypeCustom];
btnMenuOpen.frame = CGRectMake(0, 15, 40, 56);
[btnMenuOpen setImage:[UIImage imageNamed:#"side_menu.png"] forState:UIControlStateNormal];
[btnMenuOpen addTarget:self action:#selector(menu) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btnMenuOpen];
-(void)menu
{
ViewController *viewC = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
[viewC menu];
}
This is the view controller class:
-(void)menu
{
NSLog(#"menu opened");
self.mMenuView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 240, 480)];
self.mMenuView.backgroundColor = [UIColor grayColor];
self.mMenuView.autoresizingMask = 0;
[self.navigationController.view addSubview:self.mMenuView];
self.mSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 16, 220, 44)];
self.mSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.mSearchBar.backgroundImage = [UIImage imageNamed:#"slide_tab_button.png"];
self.mSearchBar.delegate = self;
[self.mMenuView addSubview:self.mSearchBar];
UIButton *btnMenuClose = [UIButton buttonWithType:UIButtonTypeCustom];
btnMenuClose.frame = CGRectMake(215, 19, 40, 44);
[btnMenuClose setImage:[UIImage imageNamed:#"side_menu.png"] forState:UIControlStateNormal];
[btnMenuClose addTarget:self action:#selector(menu_close) forControlEvents:UIControlEventTouchUpInside];
[self.mMenuView addSubview:btnMenuClose];
self.mMenuTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 61,
240, 420) style:UITableViewStylePlain];
self.mMenuTableView.delegate = self;
self.mMenuTableView.dataSource = self;
[self.mMenuView addSubview:self.mMenuTableView];
[self.mMenuTableView reloadData];
}
Now, nothing is displyed when this method is called, control goes through it but nothing happens, no delegates of table are called and neither other stuff works(button searchbar and uiview).
Please guide for the above. Thanks in advance.
Try to use of NSNotificationCenter like this
Register Notification in your ViewController.m
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(menu)
name: #"myMenuNotification"
object: nil];
}
And in your AppDelegate.m call that method using notification like
-(void)menu
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"myMenuNotification" object:nil];
}
I don't know how you are using. But I have checked code with some modification. it is working fine.
Your modified code is:
In AppDelegate method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[sampleViewController alloc] initWithNibName:#"sampleViewController" bundle:nil];
self.navController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
UIButton *btnMenuOpen = [UIButton buttonWithType:UIButtonTypeCustom];
btnMenuOpen.frame = CGRectMake(0, 15, 40, 56);
[btnMenuOpen setImage:[UIImage imageNamed:#"5.jpg"] forState:UIControlStateNormal];
[btnMenuOpen addTarget:self action:#selector(menu) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btnMenuOpen];
[self menu];
return YES;
}
-(void)menu
{
[self.viewController menu];
}
//In view Controller............
-(void)menu
{
NSLog(#"menu opened");
UIView *mMenuView;
UISearchBar *mSearchBar;
UITableView *mMenuTableView;
mMenuView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 240, 480)];
mMenuView.backgroundColor = [UIColor grayColor];
mMenuView.autoresizingMask = 0;
[self.navigationController.view addSubview:mMenuView];
mSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 16, 220, 44)];
mSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
mSearchBar.backgroundImage = [UIImage imageNamed:#"5.jpg"];
// mSearchBar.delegate = self;
[mMenuView addSubview:mSearchBar];
UIButton *btnMenuClose = [UIButton buttonWithType:UIButtonTypeCustom];
btnMenuClose.frame = CGRectMake(215, 19, 40, 44);
[btnMenuClose setImage:[UIImage imageNamed:#"side_menu.png"] forState:UIControlStateNormal];
[btnMenuClose addTarget:self action:#selector(menu_close) forControlEvents:UIControlEventTouchUpInside];
[mMenuView addSubview:btnMenuClose];
mMenuTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 61, 240, 420) style:UITableViewStylePlain];
// mMenuTableView.delegate = self;
// mMenuTableView.dataSource = self;
[mMenuTableView setBackgroundColor:[UIColor blueColor]];
[mMenuView addSubview:mMenuTableView];
[mMenuTableView reloadData];
}
Screenshot
How can i add the activity indicator beside the right bar button item (CreateNew button)?
One of the approaches that you can use is initializing the Bar Button using some custom view.
A bar minimum code which can help you get some hint is
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIView* aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 40)];
[aView setBackgroundColor:[UIColor blackColor]];
[[aView layer] setCornerRadius:8.0f];
[[aView layer] setBorderColor:[UIColor whiteColor].CGColor];
UIActivityIndicatorView* loadView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[loadView startAnimating];
[aView addSubview:loadView];
[loadView setFrame:CGRectMake(5, 5, 30, 30)];
[loadView release];
UIButton* aButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 2, 80, 35)];
[aButton setImage:[UIImage imageNamed:#"btnLogin.png"] forState:UIControlStateNormal];
[aView addSubview:aButton];
[aButton release];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:aView];
[self.navigationItem setRightBarButtonItem:barButton];
[aView release];
[barButton release];
}
This is If you do it programmatically , else you can also make use of nib. Creating bar button this way will look something like this -
You can look for more option making using of [[UIBarButtonItem alloc] initWithCustomView:aView]; method.
Hope it helps!!
For this try to customize UINavigationController Class.
Add Activity Indicator on navigationBar and control it from your ViewController.
You can add the activity indicator using the following code:
//Create an instance of activity indicator view
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
//set the initial property
[activityIndicator stopAnimating];
[activityIndicator hidesWhenStopped];
//Create an instance of Bar button item with custome view which is of activity indicator
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
//Set the bar button the navigation bar
[self navigationItem].rightBarButtonItem = barButton;
//Memory clean up
[activityIndicator release];
[barButton release];
Please refer this link for detailed code.
I have UINavigationBar with buttons than have been created using custom view. I added a target with selector for each buttom, but buttons have not respond to selector. Can you help me?
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setTitle:#"Title"];
// create custom view
container = [[UIView alloc] init];
[container setUserInteractionEnabled:TRUE];
NSString *path;
// create 2 buttons and put in a custom view
buttonList = [[UIButton alloc] init];
path = [[NSBundle mainBundle] pathForResource:#"dotActive" ofType:#"png"];
UIImage *imgList = [[[UIImage alloc] initWithContentsOfFile:path] autorelease];
path = [[NSBundle mainBundle] pathForResource:#"dotInactive" ofType:#"png"];
UIImage *imgListPrs = [[[UIImage alloc] initWithContentsOfFile:path] autorelease];
[buttonList setImage:imgListPrs forState:UIControlStateSelected];
[buttonList setSelected:TRUE];
[buttonList setFrame:CGRectMake(-30, 0, imgList.size.width, imgList.size.height)];
[buttonList setImage:imgList forState:UIControlStateNormal];
[container addSubview:buttonList];
[buttonList addTarget:self action:#selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
[buttonList setUserInteractionEnabled:TRUE];
buttonPic = [[UIButton alloc] init];
path = [[NSBundle mainBundle] pathForResource:#"dotActive" ofType:#"png"];
UIImage *imgPic = [[[UIImage alloc] initWithContentsOfFile:path] autorelease];
path = [[NSBundle mainBundle] pathForResource:#"dotInactive" ofType:#"png"];
UIImage *imgPicPrs = [[[UIImage alloc] initWithContentsOfFile:path] autorelease];
[buttonPic setImage:imgPicPrs forState:UIControlStateSelected];
[buttonPic setFrame:CGRectMake(-10, 0, imgPic.size.width, imgPic.size.height)];
[buttonPic setImage:imgPic forState:UIControlStateNormal];
[container addSubview:buttonPic];
[buttonPic addTarget:self action:#selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
[buttonPic setUserInteractionEnabled:TRUE];
// create UIBarButtonItem with a custom view
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:container];
// put item on navigation bar
[self.navigationItem setRightBarButtonItem:item];
}
Sorry Sveta,
I didn't see your complete code.Check this out.It will work for you.
- (void)viewDidLoad{
[super viewDidLoad];
[self.navigationItem setTitle:#"Title"];
// create custom view
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 30)];
[container setUserInteractionEnabled:TRUE];
// create 2 buttons and put in a custom view
UIButton *buttonList = [[UIButton alloc] init];
[buttonList setSelected:TRUE];
[buttonList setBackgroundColor:[UIColor redColor]];
[buttonList setFrame:CGRectMake(0, 0, 30.0, 30.0)];
[container addSubview:buttonList];
[buttonList addTarget:self action:#selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
[buttonList setUserInteractionEnabled:TRUE];
[buttonList release];
UIButton *buttonPic = [[UIButton alloc] init];
[buttonPic setFrame:CGRectMake(40.0, 0, 30.0, 30.0)];
[buttonPic setBackgroundColor:[UIColor blueColor]];
[container addSubview:buttonPic];
[buttonPic addTarget:self action:#selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
[buttonPic setUserInteractionEnabled:TRUE];
[buttonPic release];
// create UIBarButtonItem with a custom view
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:container];
// put item on navigation bar
[self.navigationItem setRightBarButtonItem:item];
}
- (void)changeType:(id)sender
{
NSLog(#"Change Type");
}
In Appdelegate add this code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
[navController release];
return YES;
}
I never did it programmatically.
Could you post your changeType?
It might looks like
-(void)changeType:(id)sender {
// doing something here
}
and should be declared in the interface section;
Also you could put a breakpoint on it to see if it called at all. And see the value of the variables. Please check if it called.
EDIT:
Below my code that you can insert into defaultly created Navigation-Based Application:
at RootViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *tmpInfoButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
self.navigationItem.rightBarButtonItem = tmpInfoButton;
[tmpInfoButton release];
}
-(void)buttonPressed:(id)sender {
NSLog(#"Button pressed...");
}
at RootViewController.h:
-(void)buttonPressed:(id)sender;
I've searched around and I can't seem to figure it out. I'm sure many people will have links for me and such, which I've most likely already looked at. But if someone could please just show me code to do the following:
I'd like to have a left arrow in my UINavigationBar as a "Back" UINavigationItem. How can I do this? Here is my current code in my UIViewController:
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:nil action:#selector(backButtonSelected:)];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Options" style:UIBarButtonItemStyleBordered target:nil action:#selector(optionsButtonSelected:)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"Title"];
item.leftBarButtonItem = leftButton;
item.hidesBackButton = YES;
item.rightBarButtonItem = rightButton;
[self.view addSubview:theBar];
I think this may be what you're looking for.
// in .h file
#property (nonatomic, retain) UINavigationBar *navBar;
// in .m file just below #implementation
#synthesize navBar;
// within .m method
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
navBar.barStyle = UIBarStyleBlack;
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:#"Nav Bar Title"];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]
initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:#selector(backButtonSelected:)];
title.leftBarButtonItem = leftButton;
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:nil
action:#selector(showActionSheet:)];
title.rightBarButtonItem = rightButton;
[navBar pushNavigationItem:title animated:YES];
[self.view addSubview:navBar];
You should use an UINavigationController in order to pop/push UIViewControllers on your screen. The navigation controller will add an UINavigationBar to your UIViewControllers automatically so you will not need to create them as you did.
Here is a sample. I didn't looked for memory leaks.
In the app delegate you'll find this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
MainVC *mainVC = [[MainVC alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainVC];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
MainVC is a UIViewController that represents the level 1 of the hierarchy. in it i have
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.view.backgroundColor = [UIColor redColor];
self.title = #"MainVC";
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"SecondLevel" style:UIBarButtonItemStyleBordered target:self action:#selector(secondLevelSelected:)];
self.navigationItem.rightBarButtonItem = rightButton;
}
- (void) secondLevelSelected:(id)sender
{
SecondVC *secondVC = [[SecondVC alloc] init];
[self.navigationController pushViewController:secondVC animated:YES];
}
SecondVC is another UIViewController that represents the second level of the hierachy. Here you will find the back button that you want.
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
self.view.backgroundColor = [UIColor greenColor];
self.title = #"SecondVC";
self.navigationItem.hidesBackButton = YES;
UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithTitle:#"FirstLevel" style:UIBarButtonItemStyleBordered target:self action:#selector(leftBtnSelected:)];
self.navigationItem.leftBarButtonItem = leftBtn;
}
- (void) leftBtnSelected:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}