我使用下面的函數,所以我可以在一個表中選擇2行:如何在Swift 3中訪問這些數組的第二部分?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedCellTitle = self.communityPlayers[indexPath.row]
cellId = indexPath.row
//print (self.communityPlayerIds[indexPath.row])
if let cell = tableView.cellForRow(at: indexPath) {
if cell.isSelected {
cell.accessoryType = .checkmark
}
}
if let sr = tableView.indexPathsForSelectedRows {
print("didSelectRowAtIndexPath selected rows:\(sr)")
if sr.count == 2{
print ("one ", sr[0])
print ("two ", sr[1])
}
}
}
的print("didSelectRowAtIndexPath selected rows:\(sr)")
線輸出是這樣的:
didDeselectRowAtIndexPath所選行:[[0,2],[ 0,3]]
我想只訪問每個數組中的第二個int(丟棄0)。我已用print ("one ", sr[0])
嘗試這個嘗試,但這個輸出以下:
酮[0,2]
在上面的例子我只要訪問的2
所以我可以存儲在一個單獨的變量。
如何才能訪問這些數組的第二部分? (2和3)
'sr [0] [1]'也許? – matt
優秀的馬特!謝謝!這很簡單;) – RDowns
我認爲*'sr.row'也會這樣做,'sr'是索引路徑,它包含'section'和'row'。 0是部分,1,2是行 – Honey