I am new to Objective C, but with experience of C#. I have a project named "chat secure" (on github), but I don't know how the project works without storyboard. I would like to add storyboard to the project. Is it possible to use Storyboard along with other project?
Try this code
ShopObject *obj = arrDeals[indexPath.section];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"SwipeDealViewSB" bundle: nil];
StoryBoardViewController *swipeDealViewController = [storyboard instantiateViewControllerWithIdentifier:#"StoryBoardViewController"];
[self.navigationController pushViewController:swipeDealViewController animated:YES];
But remember to name your storyboard identify and custom class is"StoryBoardViewController" demonstrate image to identify storyboard
Related
I've been using the following code untill now to get the storyboard:
NSString * storyboardName = #"myStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
However, I now have a project with multiple targets, each with their own storyboard. This code no longer works, because the name of these storyboards is different for all targets. Is there a way to get the storyboard that is set as "main interface" in my target, without knowing the name of the storyboard at runtime?
In your UIViewControllers
Use
Storyboard *storyboard =self.storyboard;
instead of
Storyboard *storyboard =[UIStoryboard storyboardWithName:storyboardName bundle:nil];
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 :)
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.
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.
How do you declare a view controller with Objective C?
Sorta depends. Just to give one example, let's say you have a new project setup using apple's "View based app" template. If you want to have a new view "slide up" and replace your current view you can do this. Add a new file to you project of type 'UIViewController subclass', and select the 'With XIB for user interface' option. Now, in you code, when you want to display this view do this:
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[self presentModalViewController:myViewController animated:YES];
[myViewController release];
This is assuming that your new UIViewController subclass name is MyViewController and the the XIB is named MyViewController (so you should have MyViewController.c(.h)(.xib)