2016-09-20 60 views
1

我有工作SWIFT 2這段代碼,它有助於獲取的UITableView單元格的行上按下按鈕:獲取的UITableView單元格的列上按下按鈕迅速3

@IBAction func commentsButtonAction(sender: AnyObject) { 
    let btnPos: CGPoint = sender.convert(point:CGPoint.zero, toView: self.tableView) 
    let indexPath: NSIndexPath = self.tableView.indexPathForRow(at: btnPos)! as NSIndexPath 
    passaValor = indexPath.row 
    performSegue(withIdentifier: "searchToComments", sender: self) 
} 

在SWIFT 3我收到此錯誤

不能調用 '轉換' 類型的參數列表 '(點: CGPoint,toView:UITableView的)'

任何想法? 謝謝。

回答

1

方法的簽名已被斯威夫特3.下改變它現在是:

func convert(CGPoint, to: UIView?) 

因此你會稱其爲:

sender.convert(CGPoint.zero, to: self.tableView) 
0

試試這個

myButton.addTarget(self, action: "connected:", forControlEvents: .TouchUpInside)) 

你需要這個

myButton.tag = indexPath.row 

func connected(sender: UIButton){ 
    let buttonTag = sender.tag 
} 

希望這會有所幫助。

相關問題