繁体   English   中英

如何快速查看tableview单元格是行还是节?

[英]How to check tableview cell is row or section in swift?

在目标C中,我曾经像下面这样检查

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {
    if (!indexPath.row)  {
         NSLog(@"section");
    }  else  {
         NSLog(@"row");
    }
}

如何用Swift做同样的事情?

indexPath.row并不意味着一节。 您可以通过编写indexPath.section获得节索引。 试想一下2D阵列。 每个部分都有自己的行。 试想一下。 希望能帮助到你。

Swift不会自动将整数转换为布尔值。 您需要使测试明确: if indexPath.row != 0 { ... }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM