【问题标题】:Navgation Controller and UIImageView in a custom cell in UITableViewUITableView 中自定义单元格中的导航控制器和 UIImageView
【发布时间】:2012-05-24 22:01:51
【问题描述】:

在我的应用程序的导航控制器中是一个 UITableViewContoller,然后是一个 ViewController。用户在 UITableViewContollrer 中选择一个项目,这将调用 ViewController。如果用户点击后退按钮,我需要直观地显示之前选择了哪个项目。用 UIImage 做这个,基本上是想隐藏或显示它。问题是我找不到一种方法来解析 UITableView 中的每个单元格并确定在再次调用 UITable 之前是否选择了该单元格。

UITableView 的一些背景知识,它基于核心数据中的一个实体。所选项目存储在核心数据中的不同实体中。

【问题讨论】:

    标签: xcode uitableview uinavigationcontroller uiimageview


    【解决方案1】:

    首先声明 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
      }
    }
    

    希望有用。

    【讨论】:

    • 我一定是做错了什么,因为我单步执行 viewWillAppear,但它从未通过 if 语句。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多