我在每个单元格中都有一个带有按钮的tableview。当点击时,我有一个didselectrow函数。我想使用索引路径从提供单元格内容的数组中获取一个值。如何将这个NSIndexpath转换为要在数组中使用的int?

最佳答案

您最可能想要的是属性。您可以看到一个example here

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

    let alert = UIAlertController(title: "Item selected", message: "You selected item \(indexPath.row)", preferredStyle: UIAlertControllerStyle.Alert)

    alert.addAction(UIAlertAction(title: "OK",
                                  style: UIAlertActionStyle.Default,
                                handler: {
                                    (alert: UIAlertAction!) in println("An alert of type \(alert.style.hashValue) was tapped!")
                                }))

    self.presentViewController(alert, animated: true, completion: nil)

}

关于arrays - 迅速,将NSIndexpath转换为Int,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28027110/

10-13 05:54