【问题标题】:Adding invisible detailview under all cell for uitableview in ios, and making visible/invisible when user tap the cell在ios中为uitableview的所有单元格下添加不可见的detailview,并在用户点击单元格时使其可见/不可见
【发布时间】:2013-09-09 13:06:32
【问题描述】:

我有动态单元格,关于单元格的信息很少。我想在另一个详细视图中向用户显示更多信息,但我不想切换另一个视图。我在另一个应用程序上看到了这种方法,在所有单元格下添加了详细视图,我尝试应用它,但我没有成功。我想我需要很多经验,我想我可以从你们那里获得更多的知识^_^

【问题讨论】:

    标签: ios uitableview detailsview


    【解决方案1】:

    使用UITableView的以下数据源方法

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        DirectoryDetails *dDetailVC = [[DirectoryDetails alloc] init];
        [self.navigationController pushViewController:dDetailVC animated:YES];\
        // OR [self presentViewController:dDetailVC animated:YES completion:nil];
    }
    

    【讨论】:

      【解决方案2】:

      我认为最好和最灵活的解决方案是为行(自定义类)制作自定义视图并使用它。

      您可以在 Interface Builder 中创建一个,将 Identifier 添加到其中。稍后创建扩展 UITableViewCell 的类,其中包含自定义元素所需的所有属性/方法。

      您可以在这样的代码中简单地使用它:

      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          static NSString *simpleTableIdentifier = @"YourIdentifier";
      
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
      
          if (cell == nil) {
              cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
          }
      
          cell.detailText = @"detailText";
      
          return cell;
      

      }

      使其可见/不可见的准备函数将改变它的可见性并调用它:

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
      {
          YourCellClass* cell = [tableView cellForRowAtIndexPath:indexPath];
          [cell showHideDetails]; //this is details.visibility = !details.visiblity; inside your class
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多