2016-04-23 81 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) 
} 
相关问题