Adding subviews inside a UINavigationController - uinavigationcontroller

I have a UINavigationController which I add a subview to.
[masterNavigationController.view addSubview:footerViewController.view];
The problem is that the app crashes (SIGABRT in main.m) when a UIButton tries to send a message to the controller.
I know I could customize the navigationcontroller's toolbar, but it would make things very complex.
Is it possible to add subviews in an navigationcontroller like this, or is something else the problem?
-- edit ---
Here is the creation code of the footerviewcontroller:
CIFooterViewController*footerViewController = [[[CIFooterViewController alloc] init];

I'm going to guess (as it's pretty common) that when you create footerViewController, you're not retaining it. Adding the view to the UINavigationController does nothing to keep that view controller around. Be sure you retain footerViewController.
Otherwise, you should post the code where you create it.

Seems like one cannot add a viewcontrollers view as subview. Making it a UIView instead and it works just fine.

Related

How to create a multiview application in xcode 4 using UINavigation Controller without a TableView?

I'm new to iPhone development. I would like to understand how to create a multiview application without TableView. The brief description of the program is: it includes three views, each one has a button. When user taps button it takes him to the next screen going in a circle. 1-2.2-3.3-1.
Two things are most important:
How to get rid of TableView and use NavigationController without it?
How to get back from the third view to the first one?
If you're just using UINavigationController with UIView's it is pretty easy. Have a view or button on view 1, that intercepts the touch action.
Shows binding a touch action to the button on your view 1
[button2 addTarget:self action:#selector(button2Pressed:) forControlEvents:UIControlEventTouchUpInside];
This shows how the method pushes a new controller to the navigation. You can do this on view 2 to take you to view 3 as well.
-(void)button2Pressed:(id)sender {
UIView view2 = [[[UIView alloc] init] autorelease];
[self.navigationController pushViewController:view2 animated:YES];
}
Finally, if you want to get back to view 1
[self.navigationController popToRootViewControllerAnimated:YES];
The best way to learn about the various options is to check out the documentation UINavigationController.

UITabBarController not using NavigationController

I'm using MonoTouch and my application setup looks something like this,
NavController
-TabBarController
-NavController
-View1
This works then I click on a tab and am directed to View1. The problem is that this was performed by the tabBarController and not the navigationController. So I get no Back button. Is there a way to capture a TabItemClicked event and manually use the NavigationController to push the View1 onto the stack? So I can get a back button.
I'm hiding the TabBar once I get to View1, so at the moment, there is no way back from View1.
Hope it may help you
http://21gingerman.wordpress.com/2009/04/06/tutorial-and-sample-code-for-iphone-app-with-tab-bar-and-nav-bar/

Substitution of detail view controller does not cause viewWillAppear to be called

I'm porting my iPhone app to iPad. On iPhone I select row in the table, and after that the next view controller is pushed to the top of navigationController (now navigation is performed on the left part of split view controller). For iPad i modified the code this way:
if (deviceIsIPad())
{
UISplitViewController *svc = (UISplitViewController *)[self findNearestParentOfClass:[UISplitViewController class]];
svc.viewControllers = [NSArray arrayWithObjects:[svc.viewControllers objectAtIndex:0],
nextViewController,
nil];
}
else
[self.navigationController pushViewController:nextViewController animated:YES];
There are no problem at iPhone code (when controller is pushed to navigation controller), but on iPad viewWillAppear: is not called (viewDidLoad is called however), while I have a reason to perform some customization right in viewWillAppear:. Why is it not called, and what should I do to force it to be called?
Much thanks in advance!
Not exactly sure what you're trying to do here but simply initializing a splitview controller and adding controllers to it does not force views to appear. You have to add the splitview controller's views to the window.
Here is the code from the Xcode Splitview template's app delegate's applicationDidFinishLaunching:
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil];
splitViewController.delegate = detailViewController;
NSLog(#"master=%#",splitViewController.viewControllers);
// Add the split view controller's view to the window and display.
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
The views in the navigation controller appear because it is already attached to the window and displaying the view of one of its controlled controllers.
Edit:
From Comments:
All initialization code you are quoted
here is already performed. Now, let's
assume one have a table on the left
controller, then he select another row
there, and want to replace right
controller with another one.
splitViewController.view is added on
the window фдкуфвн, because some GUI
elements initialized in viewDidLoad,
are properly presented on view
It sounds like your problem arises because the detail (right-side) view of a splitview controller is always visible i.e. it only appears i.e calls viewWillAppear, once immediately after first being loaded. There is no point at which the detail side has no view present. I'm not sure what entirely swapping out viewControllers of the splitview will do.
If you want to change the detail view on the fly. You need to put a navigation controller in the right side and then push and pop view-controllers in that nav in response to events in the right side controller.
Look at how the iPad iPod app works. You have a leftside view of playlist and on the right side, a list of all the songs in the playlist. Selecting a song pushes a song detail view on top the list of songs.

UITabBar inside UINavigationController programmatically?

Im writing an app that has a navigation controller as it's main menu system but I need to be able to have a UITabBar appear inside the navigation controller when the user clicks one of the buttons on the main view. I have written everything programmatically so far so would like to keep it that way if possible.
So basically, how do I show a UITabBar inside the a navigation controller programmatically?
Many thanks :)
Depending on what you need to do you can either push a UITabBarController into the navigation controller or just add a UITabBar as a subview to a view that you need it on.
- (void) viewDidLoad {
CGRect frame = ..create frame here..
UITabBar *bar = [[UITabBar alloc] initWithFrame:frame];
[self.view addSubView:bar]
}
It's that simple.

Autorotate with a UINavigationController

I am a little unclear on how to rotate views that are sitting on a UINavigationController.
I have overridden the UINavigationController object with one of my own that overrides:
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { return YES; }
I have one view on the stack on the controller and that view is loaded from a xib with two views in it. I want to switch from portrait to landscape. Normally I would handle this by changing the view from within the nib files of the view itself. Do I have to implement the rotational code within the Navigation Controller or just within my view code?
(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
That willAnimate code is what I'm used to using in the view itself, but I'm still not seeing the view being changed, and I'm thinking it may be that I need to access the view in the NavigationController and change that, or even override the same method in the Navigation Controller and do my view switching there.
Any suggestions? I've never actually done this before and just found out the TabViewControllers and NavigationControllers are both portrait mode only by default.
Turns out it wasn't possible to change the view because I was trying to changes the RootView on the Navigation Controller. I got around this by placing my own pseudo root view controller that never gets seen in the root spot on the Navigation stack. I overrode a few of the navigation controls to account for this so the functionality would continue the same and I'd be able to change my desired perceived root view as I needed to.
A start in the right direction can be found in this link:
http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller’s-root-view-controller/

Resources