在我的应用程序中,导航控制器是一个UITableViewContoller,然后是一个ViewController。用户选择UITableViewContollrer中的一个项目,这将调用ViewController。如果用户点击后退按钮,我需要直观地显示之前选择的项目。使用UIImage执行此操作,基本上想要隐藏或显示它。问题是我找不到一个方法来解析UITableView中的每个单元格,并确定在再次调用UITable之前是否选择了单元格。
UITableView的一些背景,它基于核心数据中的实体。所选项目存储在核心数据中的不同实体中。
答案 0 :(得分:0)
首先声明NSIndexPath * selectedIndexPath并创建其属性。现在在tableView Delegate:
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
{
selectedIndexPath = indexPath;
}
您已在tableView中选择了单元格的IndexPath。当点击导航栏的后退按钮时,将调用ViewControllers viewWillApper
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(selectedIndexPath)
{
//if you have custom cell then you will get custom cell which was selected just use custom cell object in place of UITableViewCell
UITableViewCell *cell = (UITableViewCell*)[YourtableView cellForRowAtIndexPath:selectedIndexPath];
//You have cell reference which was selected when one view controller was pushed in navigation controller.
// you can change image or label text which are present in your cell
// cell.ImageView or cell.labelText anything
}
}
希望它有用。