【问题标题】:Change other table view cell's data when selecting one of them选择其中一个时更改其他表格视图单元格的数据
【发布时间】:2017-07-08 09:24:09
【问题描述】:

当我点击表格视图单元格时,我需要更改另一个单元格的详细标签文本。 我该怎么做?

【问题讨论】:

    标签: ios uitableview cocoa-touch


    【解决方案1】:

    您需要为所选行存储 indexPath。您可以在 cellForRow 中放置一个大致相同的条件。

    这是排序示例:

    在.h文件中声明变量:

    int selectedIndexPath;
    

    .m

        -(void)viewDidLoad
         {
               [super viewDidLoad];
               // So it won't show any select for the first time
               selectedIndexPath = -1;
               [tableView reloadData];
         }
    
        -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            int currentRow = (int)indexPath.row;
            if(currentRow == selectedIndexPath)
            {
                // Show your base cell
            }
            else
            {
                // Show detail cell
            }
        }
        -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
            selectedIndexPath = (int)indexPath.row;
            [tableView reloadData];
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      • 2023-03-14
      相关资源
      最近更新 更多