I have worked mostly on iPhone apps. Now I need to build an iPad app. In that I need to put NavigationController in the MasterView of the Master Detail View of the iPad as we do in the UITableView in the iPhone. I mean when user selects a particular row it should navigate to another tableview with newly filled data. and user can go to the previous by pressing back button. Also On each selection I need to make change of image in the detail view.
I dont have any idea to achieve this.
Please provide any suggestions or any sample code for it.
Thanks in advance.
try this in your appDelegate didFinishLaunchingWithOptions method
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController_iPad" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
DetailViewController *detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController_iPad" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationControlle, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
This is certainly possible. There are no limitations on what you can display in the master and detail views of a split view controller.
Think of the split view as merely a view that displays two of your view controllers. They can contain anything.
If I understood what you're trying to achieve correctly then what you want to do is create a View Controller with a UITableView which will display the data in the left column. This View Controller should also have a UINavigationController which will push another view controller when you select something in the table.
So far, so good. Nothing has changed in the detail view since it in reality isn't aware of or connected to the master view in any way. When the user has moved enough steps down in the master view, and you want to change the detail view - then you can set the viewControllers-property of the navigation controller to update the detail view with whichever view controller you want to display.
Yes you can. Apple has provided a sample code called MultipleDetailViews
It shows how communication is done between master and detail using delegation.
See these Tutorials :-
http://www.icodeblog.com/2010/04/05/ipad-programming-tutorial-hello-world/
http://www.raywenderlich.com/1040/ipad-for-iphone-developers-101-uisplitview-tutorial
These will help you.
Related
In short, how can i manage to load a SPECIFIC uiview from a set of UIViews all contained in one XIB file? iboutlets? how?
In some cases i would like the first view displayed instead of the 2nd, sometimes i want the 3rd displayed instead of the 1st. they are all similar UIViews however only one can be displayed MODALLY presented.. I know which UIView to display depending on the user interaction with buttons being clicked.. however the question is how can i specifically select a certain view to be displayed and then attach it modally to present it.
In detail this is what i have done so far:
Hi,
I have three view objects inside my TestViewController.xib file like so:
This xib's 'File's Owner' is connected to a TestViewController class.
On run time i am programatically instantiating the TeamViewController class like so:
TestViewController *tVController = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
I then present the view modally like so:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ls];
[nav setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
nav.navigationBar.tintColor = [UIColor blackColor];
[nav setNavigationBarHidden:YES];
[rootViewController.navigationController presentModalViewController:nav animated:YES];
nav.view.backgroundColor = [UIColor blackColor];
self.modalNavController = nav;
[nav release];
[tVController release];
This all works and my view is loaded, however it only loads one of the views by default - automatically.
What i would like to do is to be able to know how to load only a SPECIFIC UIView when instantiating the TestViewController. One way i thought of achieving this was to create IBOutlets for them and managing which view is displayed like that? so I have created three IBOutlets within the class and then connected them from the Xib's fileown to each UIView. This connected all fine.
IBOutlet *view1;
IBOutlet *view2;
IBOutlet *view3;
I am able to do something like this:
[self.view addSubview:view2];
and this will display view2 properly, however not in the modal view as i would ideally like it when instantiating TestViewController.
Can anyone guide me in how to achieve this goal of mine?
Thanks
You should give each of the views a unique tag, then use viewWithTag:
-EDIT-
In order for this to work, you might need to do NSNib *n = [[NSNib alloc] initWithNibNamed:bundle:]
I am trying to use the UINavigationController class in Objective-C, but I am having a difficult time understanding how it should work.
Basically, I have my app. I want to use the UINavigationController to show a hierarchy of data stored in an NSArray. I currently have this data being presented in UITableView. I want to make it so a user can click on a row of the table view and be taken to more specific data about the row they just clicked. I think a UINavigationController is perfect for this.
However, my understanding of MVC in the context of Objective-C is not that good and I am confused about how to do this. I want the UINavigationController to only show up in the left half of my iPad app and I would also like the ability to hide it at times. So how do I configure this?
This sounds like the correct usage for a navigation controller.
What you will need to do is create your navigation controller and populate the root view with your view controller containing the table view. In your didSelectRowAtIndexPath you would push the detail view onto the stack. All the navigation will be set up to go back for you.
Most likely in your AppDelegate:
ListViewController *theView = [[ListViewController alloc] initWithNibName:#"ListViewController" bundle:nil];
UINavigationController *navView = [[UINavigationController alloc] initWithRootViewController:theView];
[theView release];
[window addSubview:navView.view];
[window makeKeyAndVisible];
Imagine that we have multiview apllication which is controlled by Navigation Controller. We go from the first view to second by using pushViewController method and that's not a problem but then we need to move to the third view. And the third one is a view which looks like a TabBar. How do we do that? The third view is supposed to be controlled by TabBarController, isn't it?
So how to pass the control? I declared an outlet UITabBarController * tbc and connected it to TabBarController in xib file and then i tried this in viewDidLoad:
tbc = [[UITabBarController alloc]init];
and it shows nothing.
Your help is highly appreciated
It's a bit wierd. Its more standard to have a tabBarController that switches views and some of those views may be navigation controllers. But ...
Create the UITabBarController and push it.
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
// create someView
[viewControllers addObject:someView];
// create someView2
[viewControllers addObject:someView2];
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:viewControllers];
[[self navigationController] pushViewController:tabController animated:YES];
Then, from the tabBarContoller view, based on some action, you can choose to pop it:
[self.navigationController popViewControllerAnimated: NO];
You can wire it up in the storyboard editor in the latest version of Xcode.
However, since this is very much non-standard use of the controls, you would need a very good reason as to why you would want a UI like this.
And even then, Apple's review process might turn your app down if the interface is clunky.
I have an aplication which initially there's a TabBarController, each tab is a ViewController and every one has a button which calls other controllers.
So how am I supose to structure this? Having one main rootviewController (if so, how?)? Or calling in the appdelegate only the tabBarController and in each the viewControllers inside the tab call the other controllers?
What's the best way so I can advance, go back and transition views nimbly?
Don't know if I made myself clear...
Thanks guys.
Generally you will start with the Template called "Tab Bar Application" and as of Xcode 4 starts by loading the MainWindow Nib, which hold a tab bar and the tab bar is set up in IB to have 2 view controllers, called "FirstViewController", and "SecondViewController"...
You can follow that pattern if it suites you, otherwise you may want to start with a view based application and add your own tab bar. I personally find it to be easier to control the tab bar, through the UITabBarDelegate, especially if you plan to do anything slightly esoteric.
Edit:
Basically one of two ways, if you plan to load a Navigation controller stack, or a single modal view.
1)
ThirdViewController * controller = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
UINavigationController * myNavigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentModalViewController:myNavigationController animated:YES];
[controller release];
[myNavigationController release];
2)
ThirdViewController * controller = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
either way get back to the Tab environment by calling the following on the view controller that is calling present modal.
[self
dismissModalViewControllerAnimated:YES];
Just because I am unable to find a secure way (in a sense that it can be rejected by Apple guys) to customize UITabbar, in particular UITabBarItem I am trying some workaround.
I have a main view on which I recreate a kind of UITabBar, a normal view with two buttons inside. This is (roughly) the current hierarchy:
-MainView
--placeholder(UIView)
--fakeTab (UIView)
What I want to do is, after tapping a button in fakeTab, build a UINavigationController and add it to "placeholder" view so that the fakeTab remain on top and the whole navigation happens on the placeholder level.
I already tried with this piece of code in the method that it's intercepting tap button, and it works, I can see the ipvc.view added to placeholder.
IPPlantsViewController *ipvc = [[IPPlantsViewController alloc] initWithNibName:#"IPPlantsView" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ipvc];
UIView *placeholder = [self.view viewWithTag:200];
[placeholder addSubview:ipvc.view];
But later when I call from inside ipvc, then nothing happens:
IPAttributes *ipas = [[IPFactory findPlantByIndex:indexPath.row] attrs];
[self.navigationController pushViewController:ipa animated:YES];
I find the solution myself. What I was doing wrong is to attach the ipvc controller view to placeholder. Instead of doing this:
[placeholder addSubview:nav.view];
and everything works as expected, with my fake tabbar fully customized :-)
But, as a side note, the viewWillAppear seems to be never called.
It would be interesting to know why. I partially solved by making IPPlantsViewController the delegate of the UINavigationController.