I’m using xcode 4.3 with storyboards.
this is how I am calling my secong UIViewController, called BookMenuController
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
BookMenuController* bookControll = [sb instantiateViewControllerWithIdentifier:@"contBook"];
bookControll.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:bookControll animated:YES];
how can I pass a parameter in such case? I wanna pass a integer but in the future I want to pass an NSMutableArray.
any thoughts ?
You’d do that part the same with or without storyboards: define and declare a method (or property) on your view controller class (
BookMenuController), and call that method (or set the property) to pass data to the view controller.On a (more or less) unrelated note, you’re not really gaining anything from using storyboards when you use this pattern to instantiate and transition to view controllers. Part of what storyboards are designed to help you with is eliminate some of this kind of boilerplate code. If the snipped you’ve quoted is to be invoked when the user taps on a control, you don’t need any code at all — just drag a segue in IB connecting the control to the destination view controller. (You can specify the segue type and transition style in IB, too.) If you need to control when the segue happens more precisely, use
performSegueWithIdentifier:sender:, and you can still offload segue setup from code to IB. Either way, you can then call methods / set properties on the destination view controller inprepareForSegue:sender:.