Reputation: 23
I have been trying to solve a big "thing" in my application for hours. I'm so tired that I don't even remember what word I should use instead of the "thing" word. :p
This is the first time I'm using storyboards in my app.
Im writing out X amount of buttons programmatically which later will be dependent on data from a database. As the title says, my problem is that I'm using a storyboard and can't get a grip on how to create a new view in the storyboard that the buttons then can change to. And also with some data from the first view.
Here is some code if thats helps you help me. ;p
- (void)viewDidLoad
{
[super viewDidLoad];
int heightGrowt = 0;
for(int i = 0; i < 10; i++)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(10, heightGrowt, 300, 40);
heightGrowt = heightGrowt + 50;
[button setTitle:@"First element" forState:UIControlStateNormal];
[scrollWiew addSubview:button];
}
[scrollWiew setScrollEnabled:YES];
[scrollWiew setContentSize:CGSizeMake(320, heightGrowt)];
}
If you have/know anything that can help me i would be very grateful. :)
Upvotes: 0
Views: 5629
Reputation: 167
[theUIViewControllerThatYouAreSeguingFrom performSegueWithIdentifier:@"theIdentifier" sender:theViewCallingForTheSegue];
You can name the segue in the Attributes section of the Inspector.
Upvotes: 4
Reputation: 25740
Okay, based on your comment you are on the right track.
In order to retrieve it from the storyboard, you must first go into the storyboard, select the view controller that you want to retrieve (click the yellow circle with the lined paper in it that is under the view controller - Note that you must be zoomed in to see it.) and give the "identifier" field (listed under the Attributes Inspector) a unique name which you will use to refer to this particular view controller. Let's say that we are using firstViewController
for purposes of this example.
In your buttonPressed:
function, you will need to get the view controller that you want from the storyboard and then display it when the correct button is pressed. I'm assuming that the current view was loaded from the storyboard (and if not you will need to get your reference to the storyboard a different way).
// I'm assuming that the class is UIViewController. Change this if not.
UIViewController *aViewController = [[self storyboard] instantiateViewControllerWithIdentifier:@"firstViewController"];
// Once you have retrieved it, you display it like you would any other view controller.
// I.e. if you want to push it onto a UINavigationController stack you would use:
if (aViewController != nil) {
[self.navigationController pushViewController:aViewController animated:YES];
}
Upvotes: 1
Reputation: 494
Each storyboard view has a UIViewController class set just as you would do for a separate XIB - Create a new UIViewController subclass file in your project, and set this this as the 'Custom Class - Class' property in the IB Utilities Inspector for the appropriate view in the storyboard.
You should then just be able to instantiate this UIViewController object as and when needed from your button, and Push them onto a NavigationController stack, or transition it however suits.
Check these links to a really good Storyboard tutorial:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2
Upvotes: 0