iOS 5 Storyboards and Nibs - objective-c

I have started my iOS 5 app using a storyboard, however if I want to programatically modally present a view, how can I? I can't use initWithNibName as there are no longer nob files, but a storyboard.
E.g. this will give me a blank UINavigationView and not my Interface Builder one:
setupView = [[setupController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:setupView];
[self presentModalViewController:navigationController animated:YES];
If I use a button in interface builder (in my storyboard) and link the two views with it using 'Modal' it works a charm, but I want to do it programatically.
Thanks.

Turns out I think I have been looking for performSegueWithIdentifier and it works a charm.

Beginning Storyboards in iOS 5 Part 1 explained everything in details.

Related

Why is the top of a view controller presented in a UIPopoverController cut off?

My app presents a view controller inside a UIPopoverController when the user presses a button. On iOS7 this works fine, but on the iOS8 beta the top of the view controller is underneath the popover's navigation bar. You can see the difference in the screenshots below.
I've made a really simple app that shows the problem. There's one button connected to the method shown below. contents is a very simple view controller with a yellow background and two labels in it. thePopoverController is a UIPopoverController.
- (IBAction)go:(id)sender {
self.contents = [[ContentsViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:self.contents];
self.thePopoverController = [[UIPopoverController alloc] initWithContentViewController:navController];
[self.thePopoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:TRUE];
}
Does anyone know why this happens on iOS8? Is there a way of getting it to work on iOS7 and 8, without having to hard-coded an offset? Any help much appreciated!
Cheers
I had this issue and removing UIRectEdgeTop from my view controller's edgesForExtendedLayout mask fixed it for me. So after setting self.contents, do this:
self.contents.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;

Unable to switch between UIViewControllers using storyboard

I am new to objective C so please forgive me if this is a stupid question (and I have searched!)
I am using storyboards in xcode (4.4.1) and I have 2 UIViewControllers
I am trying to programmatically switch between them (not sure if that's the right terminology?)
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"BookingView"];
[self presentModalViewController:vc animated:YES];
The above code works perfectly later on in my project, but I when i try call if in an if() in my viewdidload method in the first UIViewController it doesn't work. Help please!
You shouldn't perform such task in the viewDidLoad: method.
You're trying to present a view controller modally on top of another that's only been allocated in memory and loaded, but it's not visible yet. That means your presentation won't work. You should move your code to viewDidAppear:
I recommend you to read this guide to learn the basics about view controller delegation: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40007457
Why not self.storyboard instead of [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];?
Assuming that all your view controllers are from the same storyboard :)

Setting up and using the UINavigationController class in Objective-C

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];

storyboard and programic modal changes

starting a new project and want to try using the storyboard feature of xcode 4.2. i got the basics of how to do transitions within the story board, but how do i do it in the code (load a new view w/out the use of a button)?
do i just use the old method,
mapViewController *mapView = [[mapViewController alloc] initWithNibName:#"mapViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:mapView animated:YES];
?
EDIT:
the old way doesn't work. also tried:
MapViewController *mapView = [self.storyboard instantiateViewControllerWithIdentifier:#"MapView"];
self presentModalViewController:mapView animated:YES];
with no success.
If you want to load a view controller you made in a storyboard create a segue to this view controller, give it an identifier and call: performSegueWithIdentifier:sender:.
ok, i figured out the issue. i had uncommented the method "loadView" in the mapViewController so xcode did not use my storyboard layout.
also, both above methods do work to do a modal switch.

TabBarController inside NavigationController

Imagine that we have multiview apllication which is controlled by Navigation Controller. We go from the first view to second by using pushViewController method and that's not a problem but then we need to move to the third view. And the third one is a view which looks like a TabBar. How do we do that? The third view is supposed to be controlled by TabBarController, isn't it?
So how to pass the control? I declared an outlet UITabBarController * tbc and connected it to TabBarController in xib file and then i tried this in viewDidLoad:
tbc = [[UITabBarController alloc]init];
and it shows nothing.
Your help is highly appreciated
It's a bit wierd. Its more standard to have a tabBarController that switches views and some of those views may be navigation controllers. But ...
Create the UITabBarController and push it.
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
// create someView
[viewControllers addObject:someView];
// create someView2
[viewControllers addObject:someView2];
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:viewControllers];
[[self navigationController] pushViewController:tabController animated:YES];
Then, from the tabBarContoller view, based on some action, you can choose to pop it:
[self.navigationController popViewControllerAnimated: NO];
You can wire it up in the storyboard editor in the latest version of Xcode.
However, since this is very much non-standard use of the controls, you would need a very good reason as to why you would want a UI like this.
And even then, Apple's review process might turn your app down if the interface is clunky.