Reputation: 75
1) I am having an 2 view controller on 1st view controller having buttons as a) Local and b) International And I am using segment control on another view in which it has 2 bar Local and International Now when i perform the segue i need to get the titles or some data so i can identify that which bar should be displayed first the local one or international.
And simply performing the segue doesn't gets the data passed on button event. So how can i pass 2 different data on two different buttons by performing the segue ?
Upvotes: 2
Views: 332
Reputation: 2423
If the segue is connected to your button, then it will be the sender in prepareForSegue.so write this in prepareForSegue.
NextViewController *vc = segue.destinationViewController;
UIButton *dayButton = (UIButton*)sender
vc.titlestr = sender.titleLabel.text;
Upvotes: 1
Reputation: 3970
You can pass parameters to you view controllers inside prepareForSegue as follow example:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier]isEqualToString:@"mysegueidentifier"]){
NSDictionary *info = [[NSDictionary alloc]initWithObjectsAndKeys:
@"comment", @"type",
@"myId", @"elementId",
nil];
NextViewController *vc = segue.destinationViewController;
[vc setSegueInfo:info];
}
}
NextViewController must have a variable called segueInfo ([vc setSegueInfo:info];)
@property NSDictionary *segueInfo;
Upvotes: 0