I'm building an application based on the Utility template from Xcode, to which I have added some more views. My application structure would be as follows:
MainView (the app menu)
Flip-side view (a calculator)
UINavigationController
Settings view
viewDiDLoad: UITabBarController
- Tab1 view (options)
- Tab2 view (information text)
I can navigate correctly from my MainView to my Flip-side view, which is also the root view of the Navigation Controller. From my Flip-side view, I push a second view of my Navigation Controller (Settings view) that is configured to show an UITabBarController, with two tabs, as soon as it loads (with viewDidLoad).
If I remove the UITabBarController, I can return with no problems to my Flip-side view using "popViewController" from my Settings view. The problem comes if I load the UITabBarController in viewDiDLoad in my Settings view... the tabs work perfectly, but I'm not able to return to my Flip-side view (root view of the Navigation Controller) anymore.
I CAN return if I use the Navigation Bar of the Navigation Controller, but I want to configure my own buttons and have the Navigation Bar hidden.
So far I've tried the following methods:
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToViewController:FlipSideViewController animated:YES];
But they don't seem to work. The first two just do nothing (the screen remains as it was), and the third one does not recognize the "FlipsideViewController" (maybe because it's a delegate of the MainViewController?).
Is there a way to check what is exactly doing the "back" button of the Navigation Bar if I activate it?
Should I be using delegates?
Can I call a popViewController method in my Settings view from any of the two Tab views?
This is my Flip-side view:
- (IBAction)showSettingsView {
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:#"SettingsView" bundle:nil];
controller.title = #"Settings";
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
This is my Settings view:
- (void)viewDidLoad {
[super viewDidLoad];
tabBarController = [[UITabBarController alloc] init];
Tab1ViewController* vc1 = [[Tab1ViewController alloc] init];
Tab2ViewController* vc2 = [[Tab2ViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
}
And the method to return in one of the Tab views:
- (IBAction)backFromTab1View {
[self.navigationController popToViewController:FlipSideViewController animated:YES];
}
Thanks very much and sorry if the question is too basic!
I actually solved the problem creating my own UINavigationBar in the Settings view and using:
[self.view insertSubview:tabBarController.view belowSubview:myNavigationBar];
That inserts the rest of the view below the Navigation Bar and I still can use it to configure a button which pops the view and return to the previous screen.
It took me a while to realise the differences between "addSubview" and "inserSubview + belowSubview". Sorry about that!
Related
In my application my first Page is a UITableviewController. Then I add a subView in UIViewcontroller like:
viewcontrollername * prod=[[viewcontrollername alloc]init];
[self.view addSubview:prod.view];
It's fine, but My problem is in UINavigation controller not working in viewcontroller page(doesn't Navigate to another Page). I have implemented it in click event:
prod *login=[[prod alloc]init];
UINavigationController *navCtrl= [[UINavigationController alloc] init];
[navCtrl pushViewController:login animated:YES];
[login release];
And
prod *login=[[prod alloc]init];
[self.navigationController pushViewController:login animated:YES];
[login release];
But it doesn't Navigate to another Page.
Use this code when you init the navigation controller :
UINavigationController *navigationCtrlSlideShowSetting = [[UINavigationController alloc] initWithRootViewController:yourviewcontroller];
Thanks
It looks like navCtrl hasn't been added to the view hierarchy. Either you add it as a subview to the window or make it the rootViewController.
Your first view controller should be the root view controller of the navigation controller.
initWithRootViewController
Alternatively you can add the newly created navigation controller to your viewcontroller.
[self.view addSubview:navCtrl.view];
Once this is done you can push view controllers to the navigation controller.
EDIT:
You need to have a back button in case you do not have a way to come back to main screen. The better option is to use navigation controller for the main screen and go on pushing views onto the stack.
I have created a new Tab Bar Application template in xcode. How should I properly setup a new view that animates in (Slide Up) when a button is pressed? I've seen this done using the NavigationController.
I've added a navigation bar and a button with an action that adds a sub view using this code:
(IBAction)newPost:(id)sender
{
// Load UIViewController from nib
PostViewController *screen = [[PostViewController alloc] initWithNibName:#"PostViewController" bundle:nil];
// Add to UINavigationController's stack, i.e. the view for this UITabBarController view
[self.view addSubview:screen.view];
// Release music, no longer needed since it is retained by the navController
[screen release];
}
I'm not sure if this is what you're asking, but if you just want a new view controller to present itself modally upward just do this.
1.) New File --> View Controller
2.)
newViewcontroller *viewController = [[newViewcontroller alloc] initWithNibName:#"newViewcontroller" bundle:nil];
[self presentModalViewController:viewController animated:YES];
[viewController release];
I have a very simple question. I have a view controller. In the view controller, i have added few buttons. On button click I have to start a tab bar controller (each of which has navigation controller).
Code Snippet:
- (IBAction) pushNewsAlertsController:(id)sender {
//Create a navigation controller
UINavigationController *FirstNavController = [[UINavigationController alloc] init] ;
//create the view controller (table view controller)
FirstViewController *firstViewController = [[FirstViewController alloc] init];
[FirstNavController pushViewController:firstViewController animated:YES];
//Create a navigation controller
UINavigationController *secondNavController = [[UINavigationController alloc] init] ;
//create the view controller (table view controller)
SecondViewController *secondViewController = [[SecondViewController alloc] init];
[secondNavController pushViewController:secondViewController animated:YES];
// Set the array of view controllers
tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil] ;
//Add the tab bar controller's view to the window
[self.view addSubview:tabBarController.view];
}
I am able to add the tabviews and navigation controller. The problem is I am unable to get back to the main view once the button is clicked.
Can anyone guide me on how to get back to the previous view so that I can click other buttons.
In this case, I would consider presenting the tab bar controller modally. It's a cleaner way of organizing your views in the same way the user interface is organized. You can just dismiss the modal presentation to go back to the previous view. Read View Controller Programming Guide for iOS about similar advice and examples.
Not sure if I get what you are trying to do, but if you want the tab bar controller view to disappear again, the only way would be the inverse of
[self.view addSubview:tabBarController.view];
which could be
[tabBarController.view removeFromSuperview];
I must say it looks like an odd construction you're building, but it may work nevertheless.
I am relatively new to the whole MVC way of looking at things.
I have an application that is based on the "Utility" Application template. Everything in the MainView and FlipsideView is working great but now I need to add a TableView and Navigation Controller to the flipside. Without the navigation bar being on the MainView.
So only once the user has tapped the info light button will the nav bar display on the flipside with a table view.
I have been able to impliment the Table View on the side and populate it with data from an array.
I am now struggling to link in a navigation controller so that the tableview can become interactive.
When I place the nav bar code into the app delegate it appears on the MainView and not the flipside view.
Where do I place the navigation bar code so that it will display on the flipsideview. I cannt seem to get the code in the right place.
Also I am not sure I have the right code, do I put the UINavigationController code in the FlipSideViewController.m ?
I am not grasping the concept of the naivgation controller fully I think . . .
Here is the code to bring up the FlipView
- (IBAction)showInfo
{
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Now I need to get the TableViewController to have a navigation controller and a table view
Thanks in advance.
After you create your table view controller, create a navigation controller that contains this table view controller as the root. Then, present this navigation controller modally, instead of your table view controller.
I prefer to do this programmatically, so here's the code I use:
- (IBAction)showInfo
{
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
controller.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller release];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:YES];
[navController release];
}
In your table view controller, set up its navigation item to contain a button that, when tapped, causes your main view controller to dismiss the modal navigation controller (thus flipping back to itself).
I have a view controller alike contacts in iPhone. The code is something like this,
tabBarController = [[UITabBarController alloc] init];
friendsVC = [[RemittanceFriendsVC alloc] initWithNibName:#"RemittanceFriendsView" bundle:nil];
friendsVC.friendsArray = [[RemittanceModel getInstance] friends];
UINavigationController *friendsNVC = [[UINavigationController alloc] initWithRootViewController: friendsVC];
[controllers addObject:friendsNVC];
tabBarController.viewControllers = controllers;
The RemittanceFriendsVC is UITableViewController, clicking on a cell takes to details view. I have 'modal' variable set in the ViewController (VC)to know if its loaded as modal or not. Since its part of a tab bar item, (non modal view) it works fine. But when I am loading it as modal VC, when I click on a table cell, I want to dismissmodalview, but it did not dismiss the modal view.
In the friendVC this is not working,
-(void) didPressCancelButton {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
What I wanted to do is, use the same VC as a tab bar item and sometime as a modal VC. Isn't it possible?
okay, it was the problem with the
[self.navigationController dismissModalViewControllerAnimated:YES];
it should be,
[self dismissModalViewControllerAnimated:YES];
Then it works fine.