I have two scenes in the storyboard. Since I'm not allowed to upload images (new user), let's call them Scene 1 and Scene 2.
Scene 1: UITableViewCell with a UILabel, when this cell is selected, it takes you to Scene 2.
Scene 2: Provides users options to select in UITableView. Once an option is selected, it puts a check mark next to the selected UITableViewCell.
How do I get it when you click the Save button on Scene 2, it takes the text from the selected UITableViewCell in Scene 2, and takes the user back to Scene 1 and also populates the UILabel with the text from Scene 2?
I used storyboard to create the UITableViews. Each cell has it's own class. Thanks.
Use the delegate design pattern to allow the two objects to communicate w/ each other (Apple reference).
In general:
And as an example:
Scene 2 interface
@class LabelSelectionTableViewController
@protocol LabelSelectionTableViewControllerDelegate
- (void)labelSelectionTableViewController:(LabelSelectionTableViewController *)labelSelectionTableViewController didSelectOption:(NSString *)option;
@end
@interface LabelSelectionTableViewController : UITableViewController
@property (nonatomic, strong) id <LabelSelectionTableViewControllerDelegate> delegate;
@end
Scene 2 implementation
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[self.delegate labelSelectionTableViewController:self didSelectOption:cell.textLabel.text];
}
Scene 1 implementation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.destinationViewController isKindOfClass:[LabelSelectionTableViewController class]] == YES)
{
((LabelSelectionTableViewController *)segue.destinationViewController).delegate = self;
}
}
// a selection was made in scene 2
- (void)labelSelectionTableViewController:(LabelSelectionTableViewController *)labelSelectionTableViewController didSelectOption:(NSString *)option
{
// update the model based on the option selected, if any
[self dismissViewControllerAnimated:YES completion:nil];
}