I sending a String from a UIButton to my next UITtableviewcontroller, the string is the UIButton Title (Monday … Sunday) the string is used by the NSPredicate to filter my table information by day.
@property (nonatomic, weak) NSString *dayOTW;
- (IBAction)selectDay:(UIButton *)sender {
UIButton *dayW = sender;
dayOTW = dayW.titleLabel.text;
NSLog(@"button press = %@", dayOTW);
}
2012-05-01 06:23:21.731 passingdata[99957:fb03] button press = Monday
And segue to my next screen
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"SendWeekDay"])
{
// Get reference to the destination view controller
ViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
vc.dayOTW = dayOTW;
}
}
the first time I select the button no information is show in my table , if I go back and select the button again my table show with the correct information for that day .
what i am doing wrong ?
one more question related to the above .
I have 7 UIButtons one for each day on the week, how can segue from all the UIButtons with one segue ?
Thanks
The segue is being called before your IBAction method, so the variable is not set the first time you click it.
If the segue is connected to your button, then it will be the
senderin prepareForSegue, so you don’t really need the action method. Just get the title in prepareForSegue:To connect the same segue to all buttons, you have to ctrl-drag from each button, but give all segues the same identifier. This looks messy on the storyboard, so an alternative is to create a single segue directly from the source view controller, and in the action method (which you would need in this case, and would be connected to all of your buttons) call
performSegueWithIdentifier:sender::This would then pass the button to the
performSeguemethod as the sender, so you can use the code outlined above.