swift,将NSIndexpath转换为Int

Vin*_*ent 5 arrays int uitableview didselectrowatindexpath

我有一个tableview,每个单元格都有一个按钮.当点击它时,我有一个didselectrow功能.我想使用我的indexpath从一个给出单元格内容的数组中获取一个值.如何将此NSIndexpath转换为要在数组中使用的int?

Ogr*_*des 11

你最想要的是row属性.你可以在这里看到一个例子.

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)

}
Run Code Online (Sandbox Code Playgroud)