[英]How to check tableview cell is row or section in swift?
In objective C i used to check like below 在目标C中,我曾经像下面这样检查
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!indexPath.row) {
NSLog(@"section");
} else {
NSLog(@"row");
}
}
How to do the same with Swift? 如何用Swift做同样的事情?
indexPath.row it didn't meant a section. indexPath.row并不意味着一节。 You can get the section index by writing indexPath.section .
您可以通过编写indexPath.section获得节索引。 Just think of an 2D array.
试想一下2D阵列。 Every section has it's own row.
每个部分都有自己的行。 Just think of it.
试想一下。 Hope it helps.
希望能帮助到你。
Swift has no automatic conversion of integers to Booleans. Swift不会自动将整数转换为布尔值。 You need to make the test explicit:
if indexPath.row != 0 { ... }
您需要使测试明确:
if indexPath.row != 0 { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.