我对tableView所选行有I问题。当我选择它所选择的行时,但当我回到上一个导航控制器时,该行被取消选择。我可以这样做吗? iPhone记住选择了哪一行,当我按下控制器时,它记住了选定的行,它能是蓝色的吗?
发布于 2010-03-10 01:30:16
对象通常“记住”事物的方式是将它们存储在实例变量中。因此,跟踪所选行的简单方法是向列表控制器添加一个实例变量和NSIndexPath *类型的属性。然后,您可以使用该属性来存储传递给表视图控制器的-tableView:didSelectRowAtIndexPath:方法的indexPath。
然后,您的列表控制器可以覆盖继承的-viewWillAppear:方法,以便向表视图发送一条消息以重新选择该行,如下所示:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Good idea to reload the table view's cells
// in case the underlying data was changed by
// another view controller.
[[self tableView] reloadData];
// Assuming you added a selectedIndexPath property
// to your list controller...
//
if ([self selectedIndexPath] != nil)
{
// Select the row. Note that you need to be sure
// that the table view is scrolled so that the
// selected row is visible.
[[self tableView] selectRowAtIndexPath:[self selectedIndexPath]
animated:NO
scrollPosition:UITableViewScrollPositionMiddle];
// Get rid of the saved selection
[self setSelectedIndexPath:nil];
}
}发布于 2010-03-09 22:11:46
我建议通过将所选行索引保存到文件(info.plist?properties.plist)。然后,当您返回到该视图时,从文件中取回所选行,并更改所选行索引。
https://stackoverflow.com/questions/2409441
复制相似问题