0

In my app's navigation controller is an UITableViewContoller then a ViewController. The user selects an item in the UITableViewContollrer, this calls the ViewController. If the user hits the back button I need to visually show which item was selected before. Doing this with a UIImage, basically want to hide or show it. Problem is I cannot find a method that will parse each cell in the UITableView and determine if the the cell was selected before when the UITable is called again.

Some background on the UITableView, it is based on an entity in core data. The selected item is stored in a different entity in core data.

4

1 回答 1

0

首先声明 NSIndexPath *selectedIndexPath 并创建它的属性。现在在 tableView 委托中:

- (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
  }
}

希望它是有用的。

于 2012-05-25T08:51:08.727 回答