How to change/add view to rootcontroller's view in UINavigationController - iphone

I have an application where I need to have a "custom" setting page. In my delegate I add a UINavigationController's view to the window with a UIViewController as rootviewcontroller.
In the rootviewcontroller I want to have a button and when I press the button the whole view changes to the settingview that I made. I only need the code to change view.
Thanks for the help in advance.

If Settings View a UIView SubClass then In the Button Action method you can do something like this:
[self.view addChild: settingsView]; //provided that settingsView is already allocated.
If you have written down a separate UIViewController SubClass for Settings then you can do something like this in your Button Action Method:
SettingsViewController *controller=[[SettingsViewController alloc]initWithNibName:#"SettingsViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];

Related

Pushing a View Controller from a Navigation Controller nested in a UITabBarController?

Just as the title says, I have a UINavigationController nested in a UITabBarController. When the user taps on a table cell, I would like to push a view controller (which doesn't show the UITabBar). This is the behavior of the iPod app when you tap on "Now Playing."
How can this be done?
Just add this in the view controller you are pushing.
- (BOOL)hidesBottomBarWhenPushed {
return YES;
}
For example:
OrderViewController *controller = [[OrderViewController alloc] init];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
Or try to set property hidesBottomBarWhenPushed of self.tabBarController to YES.
Start with a UITabBarController project in Xcode, place a UINavigationController in each one of the tab view for the controller, and you're done! Hope that Helps!
I think hidesBottomBarWhenPushed is the way to go. There's some gotchas to keep in mind. Your setting this on the UIViewController that you're pushing, not on the tabBarController, or on the existing navigation controller.
Check here for more details: Setting hidesBottomBarWhenPushed leaves bottom bar missing after View Controller is popped
From that post, some sample code:
self.anotherViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:self.anotherViewController animated:animated];

UIBarButtonItem not reacting to click [duplicate]

From the rootViewController I navigate to a UIViewController
if (self.contr == nil) {
ExampleViewController *controller = [[ExampleViewController alloc]
initWithNibName:#"Example"
bundle:[NSBundle mainBundle]];
self.contr = controller;
[controller release];
}
[self.navigationController presentModalViewController:self.contr animated:YES];
In the UIViewController I have the method
-(IBAction) goBack:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
I added the signature to the .h file.
In the .xib file, I have a UIToolbar with a UIBarButtonItem. I connected the button to the File's Owner - goBack:
Everything appears in the screen, but when I click on the button, goBack isn't called. I also tried to do this programatically instead, but I got the same result - everything appears, but no reaction to the click.
Any ideas why it isn't working?
Edit:
I just found out something invisible is over the toolbar. If I click on a specific point (over the toolbar), then goBack: is called. Since I navigated to this screen using presentModelViewController, the navigation bar isn't appearing... but probably it's there and that's what is hiding the tool bar.
Have bind your Toolbar with File Owner?
As your UIBarButton is subview of UIToolbar so you have to bind Toolbar with File Owner.
Presenting a modal view controller do not require you to pass through a UINavigationController. I suggest you to change this:
[self.navigationController presentModalViewController:self.contr animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
to this:
[self presentModalViewController:self.contr animated:YES];
[self dismissModalViewControllerAnimated:YES];
Let me know if this helps.
Try this in the goBack method :
[self.navigationController popToRootViewControllerAnimated:YES];
If you are not hitting the breakpoint that means you did not connect them properly in the xib.

self.navigationController pushViewController not working

I have a View application with a Single UIViewController. I then add a UITableViewController through the IB, and I am trying to display the UITableViewController through a button press in the UIViewController (my main view). My button press (IBAction) contains the following code through which I am trying to push my UITableViewController view and display it:
DataViewController *dataController = [[DataViewController alloc] initWithNibName: #"DataViewController" bundle:nil];
[self.navigationController pushViewController:dataController animated:YES];
[dataController release];
My DataViewController is not at all getting pushed into the stack and displayed,
Also I have checked that in the code above, self.navigationController=nil
Probably this is the source of the problem. If so, how to rectify it?
Please help.
UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:yourfirstviewController];
[self.window setRootViewController:navCtrlr];
navCtrlr.delegate = self;
navCtrlr.navigationBarHidden = YES;
Create navigation controller in appdelegate.m then you can navigate to any uiviewcontroller
You need to actually create a UINavigationController. The navigationController property tells you whether your DataViewController is currently in a UINavigationController's hierarchy; if not (as in this case), the navigationController property returns nil.

UIView disappears after modalViewController is removed from superview

In my app I have a tabBarController and in it a navigationController. One of my view controllers is a TableViewController and under the navigationBar i added a uiView as a subview to the view like this:
rectangleInfo = [[UIView alloc] initWithFrame:CGRectMake(0,0,[[UIScreen mainScreen] applicationFrame].size.width,26)]; rectangleInfo.autoresizingMask = (UIViewAutoresizingFlexibleWidth); rectangleInfo.backgroundColor = [UIColor darkGrayColor]; [self.view addSubview: rectangleInfo];
when I click on a cell in the tableView I push an UIViewController like this:
[feedViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[[self navigationController] presentModalViewController:feedViewController animated:YES];
After i pop the modal view for a couple of times with it from the tableViewNavigationController disappears the rectangleInfo UIView.
I pop my modalview like this:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self dismissModalViewControllerAnimated:YES];
any idea why that subview (rectangleInfo) of the tableViewController dissapears after i remove the modal view from the superview?
thank you in advance.
I'm curious as to what you are trying to do with your rectangleInfo view? By the size of it, it looks like you are trying to mimic the status bar. Why? You can just hide the status bar if you want.
Another thing you can try is to create the UIView visually in Interface Builder. Don't actually add it to your main view, but create it as a separate UIView in the XIB with the appropriate size, etc. Then create an outlet for it in Xcode and connect it. Next, add it as a subview in code when your view controller loads. See if that makes a difference. This is especially strange since you say it only disappears after popping it several times. Do you get the same problem if you push and pop the non-modal way, e.g.:
[[self navigationController] pushViewController:feedViewController animated:YES];
[[self navigationController] popViewControllerAnimated:YES];
i solved the problem by implementing correctly the viewDidLoad and viewDidUnload methods for creating and releasing my subviews.

How to switch one view with one UIButton on it,to the one with navigation controller using thatUIButton?

i am making an application with login view. This is just simple UIViewController with one UIbutton on it.I have another UINavigatioController having UITableView as RootViewContoller with many table objects at each row.The problem is : how to switch from loginview to tableview.Also there should be no navigationcontroller on loginview..and if it is not possible then there should be a way to hide it on loginview.
For loginview i have login.xib which i load it during application startup.but after clicking UIButton on loginview it should go to TableViewController having NavigationController.Is it possible to load TableviewController with NavigationController from seperate nib.if it is then how would i set delegates and view outlets on that nib.?..
I m restless to get its reply..its my request 2 all progrmmers to get a look over it..though it seems bit easy but isn't..i m hanging it with more than 2 weeks..plz help this poor-guy!
-(IBAction)goToView2:(id)sender
{
MyTableViewController *tableView = [[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil];
UINavigationController *mySocondView =[[UINavigationController alloc]
initWithRootViewController:tableView];
[self presentModalViewController: mySocondView animated:YES];
}
first u should set delegate to ur Navigation Controller . if you know how can set delegate . use this code to go to another view with UITableView and navigation controller :
-(IBAction)goToView2:(id)sender
{
UINavigationController *mySocondView =[[UINavigationController alloc]
initWithRootViewController:[[MyTableViewController alloc]
initWithNibName:#"MyTableViewController" bundle:nil]];
[self presentModalViewController: mySocondView animated:YES];
}
on your navigation view u can continue your project :)