Hashmat Khalil
Hashmat Khalil

Reputation: 1816

iOS 5 segue initialize more than one property

i did segue with one property it works but the second property causes error "no known instance method for selector..."

how many variables one can initialize when segueing?

[segue.destinationViewController setID:1 setName:@"name"];

with either of the setters it works but no more than one. any idea why? and how to set more than property?

Upvotes: 1

Views: 531

Answers (2)

Wayne Hartman
Wayne Hartman

Reputation: 18487

Override the prepareForSegue:sender: method in the originating view controller:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  UIViewController *controller = segue.destinationViewController;
  controller.ID = 1;
  controller.name = @"name";
}

Upvotes: 2

Carl Goldsmith
Carl Goldsmith

Reputation: 750

You can create an instance of the destinationViewController and edit that.

UIViewController *nextController = [segue destinationViewControler];

[nextController setID:1];
[nextController setName:@"name"];

If you are working with a custom class you will need to do it slightly differently:

YourClass *nextController = (YourClass *)[segue destinationViewController];

[nextController setID:1];
[nextController setName:@"name"];

Sorry if there are any typos. I know this works because I have used it in multiple applications.

Upvotes: 2

Related Questions