【发布时间】:2014-05-22 04:34:58
【问题描述】:
I have a UITableviewController and when a row is selected, I want to pop back to my rootViewController and have it display the text of the row in table view.现在发生的事情是在调用popToRootViewController 函数之前调用了我的常规视图控制器中的viewWillAppear,因此当它转到常规视图控制器时,它不会显示文本。我也尝试过使用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 方法,它工作正常,问题在于选择一行,我不知道为什么?
提前感谢您的帮助。我真的很感激。
【问题讨论】:
-
它是基于 stroyboard 的应用程序吗?
-
您的要求:选择一行 -> popToRootView (RegularViewController)。但是,RegularViewController 的 viewWillAppear 先发生,didSelectRow 发生在后吗?对吗?
-
我认为您发布的代码中没有任何内容。也许 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中的某些东西?
-
你的单元格上是否有任何segues?
-
是的,这是基于故事板的应用程序,我也尝试过 viewDidAppear,但它会首先被调用,但它不应该调用它。不,我没有连接到单元格
标签: ios uitableview didselectrowatindexpath poptoviewcontroller