I want to ask a question about the UI item on the UINavigationBar on the iPhone application. Im my program, there are a navigation bar and UITableView, like the following structure.
UIView (DataRootViewController.m)
|
+- UINavigationBar
|
+- UITableView
And, I want the it display the detail of the data when the user press one of the cell on the UITableView.
However, I don't know what should I do. I just create a class with UIViewController type (called DataDetailViewController.m) and leave it empty. What should I do for the next step? Which UI element should I add on the navigation bar in the detail view in order to let the user to go back to the basic page.
thank you very much.
You should be using a UINavigationController instead of trying to replicate the behavior. On your app delegate, try something like this.
RootViewController *rootViewController = [[RootViewController alloc] init];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[window addSubview:[self.tabBarController view]];
Now, this RootViewController should have a table view, and when a user taps the table you should build your detail view controller and use
[[self.navigationController] pushViewController:myDetailViewController animated:(BOOL)animated];
Related
I know different versions of this question has been asked before but I'm really stuck here. I'm trying to get my app to push a new view from my app delegate when getting:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)localNotif {
And I put the following code in there:
MyViewController *myViewController = [[MyViewController alloc]init];
nvcontrol = [[UINavigationController alloc] initWithRootViewController:myViewController];
[nvcontrol.navigationBar setTintColor:[UIColor blackColor]];
self.window.rootViewController = nvcontrol;
and from this, I get a black view (which myViewController should not have) with a black navigation bar.
What am I doing wrong here?
As I've outlined above, you can use storyboard to set the initial view controller.
Note that if you have a view controller set up in storyboard and then you create a view controller in the application delegate, the view controller you created won't look like your one in storyboard. This is because you are making an instance of the CLASS, but the program has no way to associate this with your layout.
Hey guys i`m trying to present a modal view controller inside an application with a tab bar controller. The problem is, every time the new view is presented, it on top of my tab bar.
I need to keep my tab bar even when the view is presented. Like google maps application does with his toolbar at the bottom of the screen.
How can i do that?
Thank you
By default, a modal view controller is meant to take up the entire screen (on an iPhone/iPod, at least). Because of this, it covers whatever you have on screen at the time.
A view controller presented via modal segue is meant to live on its own. If you want to keep your Navigation and TabBar, then just use a push segue to present the new ViewController. Remember to use this kind of segue, your presenting controller needs to be part of a UINavigationController already.
Use this to push a ViewController. If it is a UINavigationController it will push its linked RootViewController by itsself.
Create a viewController to push: (Using Storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
or (Using Code/Nibs)
LoginViewController *viewController = [[LoginViewController alloc] init]; //initWithNibNamed in case you are using nibs.
//in case you want to start a new Navigation: UINavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
and push with:
[self.navigationController pushViewController:vc animated:true];
Also, if you are using Storyboards for the segues you can use this to do all the stuff. Remember to set the segue identifier.
[self performSegueWithIdentifier:#"pushLoginViewController" sender:self]; //Segue needs to exist and to be linked with the performing controller. Only use this if you need to trigger the segue with coder rather than an interface object.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"pushLiftDetail"]) {
[[segue.destinationViewController someMethod:]];
segue.destinationViewController.someProperty = x;
}
}
I think you'll need to add a UITabBar to the modal view and implement/duplicate the buttons and functionality that your main bar has. The essence of a modal window is it has total control until it is dismissed.
You might try putting your UITabBarController into a NavBarController, but I'm not certain that this will work.
UITabBarController -> NavBarController -> Modal View
I have made a very simple Navigation based app (UIViewController). The view has a single button on the Main RootViewController.
Next, I made 2 classes: TabOneViewController, TabTwoViewController. All good. I then created a new Class TabBarViewController. I opened up the NIB file and dropped on a ``UITabBarController onto it. The two tabs it creates in it by default were assigned (respectively) to my TabOne and TabTwo view controllers.
strong text
Then in my TabBarViewController, I made an IBOutlet for a UITabBarController, synthesized it etc etc. I linked it up in Interface builder via the "files owner".
In the RootViewController, I linked the button to my "pushView" method, and in this pushView method, I have the following code:
- (IBAction) pushView {
TabBarViewController *controller = [[TabBarViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
The end result is it DOES push a view, but I cannot see the tab bar at the bottom, let alone any of the pages I've added to the controller.
What am I doing wrong? Why can't I link it in IB?
I am not 100% sure if that's allowed.. because you already have one tabBarController as rootViewController, and you dropped one more tabBarController as first tab controller, tabs ll overlap, considering amount of real estate you have on your iPhone, it make sense to not allow a tabViewController inside another
First, you need to allocate your view controller with your nib:
TabBarViewController *controller = [[TabBarViewController alloc] initWithNibName:#"YourNibName" bundle:nil];
Secondly, in IB, click the UITabBarController and go to the identity inspector and make sure you select your custom class. That said, unless you are overriding or adding some functionality you probably don't need the custom class at all, simply use a UITabBarController directly:
UITabBarController *controller = [[UITabBarController alloc] initWithNibName:#"YourNibName" bundle:nil];
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];
I have a UITabBarController, which is the second item in a UINavigationBarController. Within the UITabBarController are a couple of views, one of which is a UIViewController subclass called AccountViewController. Got that?
Login View Controller -> UIViewController + UITabBarController - > Account View Tab -> Button
I want to use a button - Logout - to pop back to the Login view. How would I do that?
Assuming you are creating the UITabBarController within one of the UIViewControllers which are part of the string of view controllers within the UINavigationController where you have done something similar to this:
UITabBarController *mytabs = [[UITabBarController alloc] init];
[self.view addSubview:mytabs.view];
mytabs.delegate = self; // This is key to getting back your UINavigationController
You can call this from within one of the UIViewControllers that are added to your mytabs.viewControllers array like so:
[[(UIViewController *)self.tabBarController.delegate navigationController] popViewControllerAnimated:YES];
You can also specify if you want it to go to a specific viewController index in the UINavigationController stack ( just in case your Login viewController isn't the next one down or the root view controller ).