Does the navigation controls and other controls have to be within the appDelegate? - uitableview

Is it possible to start your project with a single view controller, then on the second or third view controller implement the navigation controller, then maybe on the forth view controller implement the tab view controller? Or does this type of project need to be a storyboard project?
My dilema at the moment is that I start with just one single view controller that has a round rect button that takes you to the second view controller. From the second view controller, I would like a navigation controller with an embedded table view that will take me back and fourth from the second to the third view controller. I've been trying for hours putting the necessary code into each .h and .m file but I keep hitting brick walls.
Thanks in advance.

a. You can of course present several regular view controllers then add a UINavigationController at a later stage. When you need to present the navigation controller, you can embed your detail view controller inside one as follows:
(code is in the view controller which you want to display the detail view controller from)
DetailViewController *detailVC = [[DetailViewController alloc] init];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detailVC];
[self presentViewController:detailNav animated:TRUE completion:nil];
b. It is not allowed to have a UITabBarController inside a UINavigationController (or any other view controller). You can however still use the UITabBar control and manage the rest. For an example of this, please refer to UITabBarController inside a UINavigationController.

Related

presentViewController with the tabbar

I have a app which has a tabbar which is presented in most of the ViewControllers. The problem is its not showing in an viewController which i'm presenting by this code.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:songsViewController];
[self presentViewController:navigationController animated:YES completion:nil]
I'm using the presentViewController instead of the pushViewcontroller, cause i want to customize the navigationBar in this view.
How can i present my standard tabbar which i've created using storyboard?
When you use presentViewController:animated:completion, you are presenting the view controller modally, meaning it is not being contained within any of your existing containers like a UITabBarController or anything like that. So if you want something to show up when you present a UIViewController modally, it must be contained within the view controller that you're modally presenting. So from the looks of it, you're simply presenting a UINavigationController with your songsViewController contained within it. If you want to keep your UITabBar showing, either you need to add one to the view you're presenting, or you need to change your code so that you're not presenting a view controller modally here. And to add a second UITabBar for the modal view that matches the UITabBar that you were already presenting, it will make your app work rather strangely, so I would suggest trying to change it so you're not having to present a modal view at all.

Adding viewcontrollers to navcontroller with storyboard

I have a basic storyboard setup where I load my NavViewController, which then points to initial view controller. I then have several additional view controllers all daisy chained together via segues in a linear fashion. When I initially launch my application i run the following in my NavControllerViewController.m
(void)viewDidLoad
{
[super viewDidLoad];
NSArray * controllerArray = [self viewControllers];
NSLog(#"view controllers: %#", controllerArray);
}
The log only shows the very first root view controller (the one directly 'connected' to the nav controller). All over view controllers are missing from the stack. I was under the impression that if a view controller was on my storyboard that it would automatically be added to the nav controller?
If this is not correct, would a good alternative be to instantiate each VC, from the calling VC? For example, if I wanted to transition from VC1 to the VC2, would I put the following code in VC1:
UIViewController *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:#"vc2"];
[self pushViewController:vc2 animated:YES];
Or possibly:
[self performSegueWithIdentifier:#"vc2Segue" sender:self];
They are all able to be reached by segues, but they are not instantiated or pushed onto the stack until you segue to them.
You could use the self perform segue tactic, or the push view controller, or, alternatively, if it is in response to a single button click, just control drag from that button to the next view controller and Xcode does all the rest of the work for you.
If I understand your question correctly, you have a storyboard setup looking similar to the below screen shot.When an application loads this storyboard it will definitely have only one view controller in the navigation controller stack and that will be the root view controller.
Because other view controllers are still not pushed into the navigation controller stack.
In the Viewcontroller-1, you could see a button some Action, I have created a push segue from that button to the Viewcontroller-2.Once you tap that button, second view controller will be pushed to the navigation controller stack.
If you print the viewcontrollers count now, you should get the count as 2.
Repeat the same in the View Controller-2, now you can see the count bumps to 3. Because now we have three view controllers pushed into the navigation controller stack.
Press the back button to pop the view controllers and could see the view controllers count coming down, that's because view controllers are now being removed from navigation controller stack.
As AdamG stated, the UIViewControllers will not be pushed on to the stack until you segue to them.
To set a segue, select a UIViewController and control+drag the connection to the target UIViewController. Under the Attributes Inspector tab set the Storyboard Segue Identifier.
To segue to a UIViewController use the method performSegueWithIdentifier:. Before performSegueWithIdentifier: is called prepareForSegue:sender: will be called. This is where you can pass any values that the next UIViewController needs. To check which segue is being called use the segue.identifier property in prepareForSegue:sender:. After that, you can access the destinationViewController property.
If you need to manually instantiate a UIViewController use instantiateViewControllerWithIdentifer:. The identifier can be set under the Identity Inspector tab in the storyboard.

PerformSeque from button

Currently I'm writing a iOS app with Xamarin.iOS and I wrote a custom UITabbarController named BaseTabbarController. In this ViewController I made a centered raised UIButton over the TabBar to achieve something like this:
So this means that in my BaseTabbarController there is a onClick delegate for my button. When the button is pressed I would like to performSeque(push) to a new ViewController. The following code gives me the error: "Could not find a navigation controller for segue 'searchSegue'. Push segues can only be used when the source conroller is managed by an instance of UINavigationController".
So what should I do right now? I'm not sure how to fix this..
My storyboard looks like this and I'm talking about the second row.
If the button which causes push segue is on tabbar then you an not perform push segue on it because tabbar controller is supposed to be a rootview controller and to have push segue your controller must have navigation controller as container.
For example MyViewController is controller for view A and OneMoreViewController is controller for view B now you want to call view B from view A then embed view A inside navigation controller
// Programmatically
MyViewController *vc= [MyViewController alloc] init];
UINavigationController *nav = [UINavigationController alloc] initWithRootViewController: vc];
If you want to add that View A in tabbar then add nav object inside tabbar.
Now you can call viewB from view A using Push segue.
// and if your using storyboard then
Select the view which you want to embed inside navigationcontroller and choose Editor\Embed In\Navigation Controller from menu bar. that's it.
You've got a push segue hooked up from your tab bar controller to the navigation controller on the second row -- that's not right. That should be a relationship segue (i.e. one of the tab bar controller's view controllers, a second tab).
After Edit:
To be able to push that controller from any other controller on screen, all the base controllers in each tab will have to be a navigation controller. As long as that's true, you should be able to do this. The basic procedure would be to find out which navigation controller's stack is onscreen (with the tab bar controller's selectedViewController method), and perform a push in code from that navigation controller, using pushViewController:animated:. In the storyboard, you would want to have the controller you're pushing be disconnected from everything (no segues), and have an identifier, so you can get it from the storyboard to do the push.

UINavigationController shows black screen after pushing a view

I have a storyboard application with a navigation controller an two views controllers ('A', 'B').
In the Storyboard file:
Navigationcontroller is the initial view controller. view controller 'A' is connected to the Navigationcontroller as rootcontroller. View controller 'B' is in storyboard but not connected to any view controller.
when i programmatically try to push view controller 'B' onto the navigationcontroller from inside view controller 'A' with:
B *controllerB = [[B alloc] init];
[self.navigationController pushViewController:controllerB animated:YES];
all i get is a transition to a black screen.
i checked the navigationController property in view controller A at runtime and it´s not nil.
I do not instantiate the navigationController by myself, I let storyboard do the work (maybe that´s the problem). But I think it should be possible to "manually" push view controller to a navigation controller created by storyboard.
When I connect a segue from a button to 'B' in storyboard everything works fine.
Only programmatically it does not work, only shows a black screen inside the navigationcontroller.
Maybe someone could help me with this issue.
I haven't used storyboards yet so this answer is from a glance at the docs. It looks like you can't alloc/init a view controller from a storyboard. You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
The accepted answer didn't work for me. I was already using instantiateViewControllerWithIdentifier to navigate to view controller in different storyboard. I am using xcode7.2 and Swift.
I am navigating from storyboard1, some view controller's button action.
Destination is to initial Navigation controller of Storyboard2.
Still I get black screen.
The problem was storyboard2's Navigation controller linked to 1st view controller was linked via show.
Solution:
Delete the link between Nav controller and 1st view controller. Now link it using root view controller. (Ctrl+Click on Navigation controller and drag it to the View controller and Select the option "root view controller")

iPad: Merge concept of SplitViewController and NavigationController in RootView?

I'm having trouble merging the two concepts of using a SplitViewController in my main view and having the "RootView" controller that controls the left panes popup/sidebar table view.
I want to have the left "RootView" act as a navigation menu, but how do I do this when the RootView is tied through MainWindow.xib into the left pane of the SplitView?
Basically, I want the left navigation to work just like the built-in email applications folder drilldown navigation. Is there an example iPad project out there that uses both SplitView and a NavigationView for the left/Root pane?
After you create a SplitView project, open up the RootViewController.m file and look at the -tableViewDidSelectRowAtIndexPath method. You'll see that the item that you clicked is then set as a property of the DetailViewController.
The design you're looking for would require that you push another view controller onto the navigation stack. So if you imagine the e-mail application, when a user picks a folder, the detailView is not updated, but the next level of the Inbox is pushed onto the stack. When a user selects a message from the inbox, the detail view is updated with the message contents, and the RootViewController just stays where it's at.
in the -tableViewDidSelectRowAtIndexPath method, declare your new view controller
NextViewController *nextView = [[NextViewController alloc] initWithStyle:UITableViewStylePlain];
//This assumes you have another table view controller called NextViewController
//We assign it to the instance variable "nextView"
[self.navigationController pushViewController:nextView animated:YES];
//tells the navigation controller to "slide" the "nextView" instance on top
//if animated:NO it wouldn't slide, it would just "update"
[nextView release];
//release the viewController, it's now retained automatically by the NavigationController
Does this make sense?

Resources