0

I have an NSArray tablePeople which makes up my UITableView on my 1st View Controller PeopleController. I have a UILabel personsName on my second View Controller PeopleDetailsController which I want to update with the contents of cell.textLabel.text of each row in my TableView. I have this method but it's not working:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    ((PeopleController *)segue.destinationViewController).delegate=self;
    if ([[segue identifier] isEqualToString:@"toPeopleArticle"]) {

        NSIndexPath *indexPath = (NSIndexPath *)sender;

        PeopleDetailsController *mdvc = segue.destinationViewController;
        mdvc.personsName.text = [self.tablePeople objectAtIndex: indexPath.row];
    }
}

I also have this code when the cell is selected:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"toPeopleArticle" sender:indexPath];
}

I have to note that PeopleDetailsController is a modal view and PeopleController is a navigation view controller.

EDIT: The text on the UILabel on the 2nd VC is just not being updated, it stays the same, that's the whole problem.

4

1 回答 1

1

更改以下内容

PeopleDetailsController *mdvc = segue.destinationViewController;
mdvc.personsName.text = [self.tablePeople objectAtIndex: indexPath.row];

PeopleDetailsController *mdvc = segue.destinationViewController;
mdvc.personsNameString = [self.tablePeople objectAtIndex: indexPath.row];

其中 personNameString 是 PeopleDetailsController 中 NSString 类型的属性

现在在 PeopleDetailsController viewDidLoad 或 viewWillAppear 函数中将标签的值设置为属性的值

mdvc.personsName.text = personsNameString;
于 2012-06-01T19:41:37.140 回答