2016-04-23 83 views

回答

4

if cell.selected {是正確的路要走。

if let cell = tableView.cellForRowAtIndexPath(someIndexPath) { 
    if cell.selected { 
    print("This cell is selected") 
    } 
} 

Update: Swift 3

if let cell = tableView.cellForRow(at: someIndexPath) { 
    if cell.isSelected { 
    print("This cell is selected") 
    } 
} 
0

您需要實現委託方法didSelectRowAtIndexPath

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { 
    print("cell selected at row \(indexPath.row)") 
} 
0

你可以做這樣的方式,獲取indexPath

var someIndexPath: NSIndexPath = tableView.indexPathForSelectedRow() 

取消時,它實際上是用細胞的IsSelected屬性選擇。

var cell: UITableViewCell = tableView.cellForRowAtIndexPath(someIndexPath) 
if cell.isSelected { 
    tableView.deselectRowAtIndexPath(someIndexPath, animated: true) 
} 
相關問題