NavigationItem in Master/Detail application - ios

I wrote a Master/Detail Application by using the Master/Detail template of XCode. After starting the app, the title of the navigation button for the master view is just "Master". Now I waant tio rename that button, but unfortunately I don't know how to access this button.
In appdelegate.m there is the following code to initialize the views:
MasterViewController *masterViewController = [[MasterViewController alloc] init];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController]
I tried these ways without success:
masterViewController.navigationItem.title = #"newTitle";
or
masterNavigationController.navigationItem.title = #"newTitle";
As I wasn't sure, if the name of the button is just the title of the view behind idt, I also tried that:
masterViewController.title = #"newTitle";
Nothing worked. But as the title of the button is "Master" and I definitely didn't set it, I believe there must be some way to set it. Does anyone know how to do it?
Just to show the button:

If you would have created Master/Detail application using Master/Detail Template, then go to your "MasterViewController.m" file and change the string "Master" as you wanted. See the below image it would be like this in your MasterViewController.m.
UPDATE:
and also change the barButtonItem name in the DetailViewController.m as like below. This will do the trick.

try self.navigationItem.title = #"newTitle"; inside viewDidLoad() of MasterViewController.m file. or self.title = #"newTitle" inside the init() method. HTH.

I assume that you are trying to change the title of the back button property.
This is done by putting the following code in the -viewDidLoad method of MasterViewController.
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"newTitle" style:UIBarButtonItemStyleBordered target:nil action:nil];

It's been a while and somehow with the current Xcode Version 8.3.2 it works different:
If you would have created Master/Detail application using Master/Detail Template, then go to your Main.storyboard and select the Master in the Master Scene and then show the "Attributes Inspector". In the Navigation item area you can change the Title.
You can do this for Master as well as Detail.

Related

SWRevealViewController project in iOS

Note: Problem solved.
Here comes the story. I am using RevealViewController in my project. I am also hiding the navigationBars:
[self.navigationController setNavigationBarHidden];
My project can be seen in the picture below and the "menuButton" is implemented in the tabBarViewController.
Since the navigationBar is hidden due to my interface looks, all tabViews (HomeViewController) will not show the menuButton and the navigationBar as supposed to. I am not using panGestureRecognizer to trigger the menu aswell.
This means I have a problem to trigger the menu via a normal button in HomeViewController. The menuButton-event is placed in tabBarViewController.m:
_menuButton.target = self.revealViewController;
_menuButton.action = #selector(revealToggle:);
So I tried to call a method from HomeViewController to fire the button in tabBarViewController like this:
HomeViewController.m
- (IBAction) onMenuClicked: (id)sender{
tabBar = [[tabBarViewController alloc] init];
[tabBar setupMenu]:
}
tabBarViewController.m
-(void) setupMenu{
[_realMenuButton sendActionForControlEvents:UIControlEventTouchUpInside];
[_realMenuButton addTarget:self.revealViewController action:#selector(revealToggle:) UIControlEventTouchUpInside];
}
In this example I tried to make the realMenuButton and normal UIButton. Ive also tried as a UIBarButtonItem just to trigger the #selector(revealToggle:) But nothing happens in the app when I try to trigger the button from HomeViewController.
Not sure how I shall make this work. Any other Ideas or tricks? Please be specific if so! Regards
Yes, it will still work.
SWRevealViewController is just a subclass of a UIViewController, so you can use it at any point in the app:
By calling presentViewController:animated at some point.
By using it in a navigation stack etc.
Note that you can add gestures from SWRevealViewController to its content view controllers, which will alter the behaviour of used in a navigation view controller, but that's to be expected, and you still have full control over its behaviour.
Edit
The UI structure of your app is still not clear to me - it looks like you're trying to call revealToggle on an instance of SWRevealViewController when the VC in view is infact HomeViewController? How would this work, when SWVC is not even in view?
My best guess is that your UI structure should be as follows:
TabBarController --->(root)UINavigationController --->(root)SWRevealViewController.
Then, on your SWRevealViewController, set HomeViewController as the front view controller, and the TableViewController as the right or left view controller.
Do you mean like this?
it is possible. you can set the menu button in your tabBarController.m, like this :
UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"menu.png"] style:UIBarButtonItemStylePlain target:revealController action:#selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = menu;
self.delegate = self;
For me, my initial view controller is the login screen (obviously I don't need reveal any VC here...). then when user tap the login button,
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:yourRootVC];
LeftMenuViewController *leftMenuVC = [[LeftMenuViewController alloc]init];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:leftMenuVC frontViewController:nav];
revealController.delegate = self;
[self presentViewController:revealController animated:YES completion:nil];
I've tried it and it should work as normal. Even it isn't initial view controller

Adding a third Tab in Tab bar project

im new to iphone coding and i would like some help with a tab-bar project as i found on www.fuelyourcoding.com
He is creating a custom tabbar. He can then change color of the tab-bar instead of the standard grey color.
How can i Add a third tab? I have tried to create a "ThirdViewController" as the project contained a first and a second-viewcontroller. I've also tried to copy all the information i thought could affect the tabs, and inserted "ThirdViewController", where it previously said "SecondViewController" and so on.
It's hard to describe, but here is the link if someone would be kind to have a look at it.
http://fuelyourcoding.com/files/files.zip
Thanks!
In general, you create a tab bar controller and three view controllers. You add these three view controllers to the tab bar controller and add the tab bar controller as the root view controller of the app delegate. There's not a lot that can go wrong with this idea, but if you can show more code, that will be great.
Here's the example:
ViewController1 *v1 = [[ViewController1 alloc] init];
ViewController2 *v2 = [[ViewController2 alloc] init];
ViewController3 *v3 = [[ViewController3 alloc] init];
self.tabBarController.viewControllers = #[v1, v2, v3];
self.window.rootViewController = self.tabBarController;

pushViewController does not cause new controller to draw view

Preface: I am not using *.xib files.
I instantiate a UINavigationController in a class that effectively serves as my 'rootViewController'. This 'rootViewController' also has two UITableViewController members that are drawn on different sections of the iPad screen. One of which is set as the root view for the navigation controller. Let's call it tableViewControllerA.
The problem is, when I invoke pushViewController on a valid UINavigationController, I see no effect:
[tableViewControllerA.navigationController pushViewController:tableViewControllerX animated:YES];
I've gathered from the posts I've searched today, that this push method should in turn cause the screen to redraw the top of stack controller.view. This is not what I'm seeing.
It seemed there was a disconnect in my implementation, and it was time to reference a working example in my environment (xcode 4.0). Assuming the canned templates would provide a working basis, I created a new navigation-based applications. I simply modified didFinishLaunchingWithOptions: as follows.
UIViewController *view1 = [[UIViewController alloc] init];
UIViewController *view2 = [[UIViewController alloc] init];
view1.title = #"view1";
view2.title = #"view2";
[self.navigationController pushViewController:view1 animated:YES];
[self.navigationController pushViewController:view2 animated:YES];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:view1];
[view1 release];
[view2 release];
I found similar results. When I launch the simulator the screen title reads the title of whatever the self.window.rootViewController is pointing at. With the code as is, the title of the resulting top screen reads "view1". When I initWithRootViewController:view2, the resulting top screen reads "view2".
So please tell me I'm stupid cuz xyz...
Thanks.
Here are some references and suggestions:
Simple tutorial for navigation based application:
http://humblecoder.blogspot.com/2009/04/iphone-tutorial-navigation-controller.html
Here is another one to create the step by step navigation controller and adding the views:
http://www.icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/
and here a bit advance with navigation + tab bar controller:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningToolbarandNavigationControllers/CombiningToolbarandNavigationControllers.html
Without seeing your code, I have 2 theories:
Your syntax and calls are wrong when you do the push. Use this as a model:
-(void)Examplemethod {
AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:#"AnotherClassView" bundle:nil] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
}
You are never adding the navigation controller to the view hierarchy which never adds the view either. Take a look at this.

Push a view from a TabBarController programmatically created

I have created a tab bar controller as follows:
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
NSMutableArray *tabsArray = [[NSMutableArray alloc] init];
//tab1: dive info
LogsDetailDive *logsDetailDive = [[LogsDetailDive alloc] initWithNibName:#"LogsDetailDive" bundle:nil];
[logsDetailDive initWithLogSelected:logSelected:siteSelected];
logsDetailDive.title = #"Info";
logsDetailDive.tabBarItem.image = [UIImage imageNamed:#"/images/logs.png"];
[tabsArray addObject:logsDetailDive];
//tab2: deco info
...
//tab3: equipment info
...
//tab3: computer info
...
tabBarController.viewControllers = tabsArray;
[logsDetailDive release];
[self.view addSubview:tabBarController.view];
This tab controller is pushed from a previous table view into the navigation controller.
What I'm trying to get now is to show another view pushed from a tableview in LogsDetailDive, but I really cannot understand what I am missing, since it doesn't work.
Can you suggest something?
Thanks
UITabBarController reference
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
So the bottom line, this should not be done, and will cause some problems. If you need a tabbar layout you should instead use a toolbar.

iPad - multiple UIBarButtonItem

I have UINavigationController and I`ve placed UIListView in it. Now I want to add multiple BarButtons to left side of navigation bar. How is that possible? I managed to add one button there via code but not multiple.
Edit: Buttons added via IB to NavigationBar of UINavigationController aren`t visible at all. What could cause the problem?
I`ve created UINavigationController in .h file and used this in .m and pushed another view (that TableView):
navigationController = [[UINavigationController alloc] init];
[window addSubview:[navigationController view]];
tableOfContents *tableOfContentsViewController = [[tableOfContents alloc] init];
[navigationController pushViewController:tableOfContentsViewController animated:NO];
[tableOfContentsViewController release];
Edit 2: I solved second problem. So the first question only remains. Multiple BarButtonItems ...
iOS 5.0 has apis to do this. Check the following properties of UINavigationItem Class
leftBarButtonItems
rightBarButtonItems
leftItemsSupplementBackButton
The only way you can do this is to add the UIBarButtonItem to a UIToolBar and make a UIBarButtonItem with the UIToolBar as the customView.
There are many examples on the web, check out:
http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html

Resources