How to add NavigationBar with Editbutton on left to the Uitable In Iphone?
-
20-09-2019 - |
Question
In my iphone application i have added the Uitable view. While launching the application the table is showing the No. of rows which I want. Now I want to add the Navigation bar to the UiTable, also I want to add the edit button on the left side of the navigation bar.
How to add the Navigation bar in the UiTable view in iphone? I don't want to use the UiNavigation Based application. I want to add using the code. If anybody has any useful code or any other useful link or other solution,which would be appreciated. Please be needful.
Solution
Easy assuming you have your list managed by a UITableViewController
, and aslo bite down ont he bullet and actually use the UINavigationController
as you should. Then override your viewDidLoad
as this:
-(void)viewDidLoad;
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [self editButtonItem];
}
If you for some strange reason really do need to use your own UINavigationBar
, then you have to add some extra code. Perhaps something like this:
-(void)viewDidLoad;
{
[super viewDidLoad];
UINavigationBar* navBar = self.myOwnStupidNavigationBar;
UINavigationItem* navItem = self.navigationItem;
navItem.leftBarButtonItem = [self editButtonItem];
navbar.items = [NSArray arrayWithObject:navItem];
}
But think not twice, but ten times over, if you really have a good reason not to use UINavigationController
that gives you allot of nice functionality for free.