I’m trying to update a UITextView’s text property, after a segue, which happens after a row of a table view is tapped.
here is my code
MasterViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"4 Choices"]) {
NSLog(@"prepareForSegue is called");
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
NSString *questionContent = [[selectedObject valueForKey:@"questionContent"]description];
self.questionContent = questionContent;
[segue.destinationViewController setTextViewWith:self.questionContent];
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelectRowAtIndexPath is called");
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
NSNumber *questionID = [selectedObject valueForKey:@"qID"];
int i = [questionID intValue];
if (i == 1) {
[self performSegueWithIdentifier:@"4 Choices" sender:self];
}
else
{
[self performSegueWithIdentifier:@"5 Choices" sender:self];
}
}
DetailViewController.m
-(void)setTextViewWith:(NSString *)aText
{
self.questionText = aText;
NSLog(@"setTextViewWith is called");
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.questionView setText:self.questionText];
NSLog(@"viewWillAppear is called");
}
EDIT 1 : change the code to set the text at ‘viewWillAppear’
EDIT 2 : add ‘didSelectRowAtIndexPath’
Note : the segue was pointed from MasterViewController to DetailViewController (not from the
tableViewCell)
Thanks for your help : )
The text view may not be loaded at the prepareForSegue point. I’ve only just started with storyboards and have found that I had to set string properties on the destination view controller instead, then update the UI components in viewDidLoad or viewWillAppear.