2012-07-18 49 views
0

我想操纵我的UITableView中的表格单元格,因为它从其详细视图返回,以提醒用户他们最后选择了哪一行。 UITableView是在IB中创建的,目前没有用于UITableView或任何其他句柄的@property或自定义类。很明显,它存在的时候,用户从详细视图回来,viewWillAppear被调用,但我没有看到我的UITableView在调试器中的任何句柄。UITableView - 从ViewWillAppear访问代码

任何简单地获取IB tableView对象句柄的方法?

// - The Containing ViewController 
    - (void)viewWillAppear:(BOOL)animated 
    { 


     [super viewWillAppear:animated]; 

     NSIndexPath *selected = [self.tableView indexPathForSelectedRow]; 

     if(selected){ 

     //Do something stylish with the last-selected row 
     NSLog(@"Last row selected was: %@",selected); 

     } 
} 

回答

0

我通过创建NSIndexPath *的类成员,并将其设置里面didSelectRowAtIndexPath方法解决了这个。然后,当viewWillAppear执行时,当用户导航返回fram表视图细节时,我有最后一个选定的行,以便我可以轻松地突出显示它或以任何我想要的方式处理它:

//The Containing View Controller 
- (void)viewWillAppear:(BOOL)animated 
{ 

    [super viewWillAppear:animated]; 

    if(self.lastSelectedRow){ 

     [self.tableView selectRowAtIndexPath:self.lastSelectedRow animated:YES scrollPosition:UITableViewScrollPositionNone]; 


     } 
}