简体   繁体   English

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

[英]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.

相关问题 如何检查 tableView 的一个单元格并取消选中 swift 部分中的单元格的 rest - How check one cell of tableView and uncheck rest of the cells in the section in swift 迅速地为tableView部分和tableView单元格填充一个数组 - Populate an array for the tableView section and the tableView cell, swift Swift:如何访问某个 tableView 部分中自定义单元格中的标签 - Swift: How to access a label in a custom cell within a certain tableView section 如何重新加载特定部分中选定的单元格以在 tableview Swift 中展开/折叠 - How to reload selected cell in particular section for expand/collapse in tableview Swift 使用Swift检查在tableview单元格中为文本字段选择的行? - Check row selected for textfield in tableview cell using Swift? 如何在swift中从tableview的每个部分中选择一行? - How do select a row from each section of the tableview in swift? 如何使用 Realm 和 Swift 从 TableView 中删除一个部分和一行? - How to delete a section and a row from a TableView with Realm and Swift? 在部分的最后一行添加一个tableview单元格 - Add a tableview cell at the last row of a section 如何在 header 部分和 swift 部分中的重复单元格中使用表格视图中的滑动按钮? - How to use swipe button in tableview for section header and repeated cell in the section in swift? 如何在TableView Cell Swift 3.0中将选中的选中标记设置为勾选 - how to set the selected check mark as ticked in tableview cell swift 3.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM