0

I have a UITableviewControllerand when a row is selected, I want to pop back to my rootViewControllerand have it display the text of the row in table view. 现在发生的事情viewWillAppear是在调用函数之前调用我的常规视图控制器popToRootViewController,因此当它转到常规视图控制器时,它不会显示文本。我也尝试过使用viewDidAppear,但它不起作用。这是我尝试过的代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"row was selected");
    user[@"school"] = [[_objects objectAtIndex:indexPath.row] objectForKey:@"title"];
    [[PFUser currentUser] saveInBackground];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

然后在常规视图控制器中:

- (void)viewWillAppear:(BOOL)animated
{
    NSLog(@"will appear ran");
    PFUser *currentUser = [PFUser currentUser];
    self.userSchoolLabel.text = currentUser[@"school"];
}

我在控制台中看到的是它打印出来

"will appear ran"

然后“选择了行”

我该如何解决这个问题,如果我popToRootViewController通过触摸另一个视图控制器上的按钮调用该方法,它工作正常,问题在于选择一行,我不知道为什么?

提前感谢您的帮助。对此,我真的非常感激。

4

1 回答 1

0

Event handling is a part of the Delegate methods. Your datasource seems to be correct as it is showing the row for you. So, may be you have not properly set the delegate of your tableview correctly. If you are using the nib then connect the delegate of your tableview or if you have use the code to draw the tableview simply check for the _yourtable.delegate =self; is set or not.

Another reason could be if there is uiview in the tableview cell then it can take your rowselection event away.

Also, if you are setting editing enabled in the tableview, it may not call the didSelectRowAtIndex: method... for detail see here

于 2014-05-22T04:49:37.413 回答