overrIDe func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell { let cell = tableVIEw.dequeueReusableCellWithIDentifIEr("cell",forIndexPath: indexPath) as requestsCell // Configure the cell... cell.name.text = requested[indexPath.row] imagefiles[indexPath.row].getDataInBackgrounDWithBlock{ (imageData: NSData!,error: NSError!) -> VoID in if error == nil { let image = UIImage(data: imageData) cell.userImage.image = image }else{ println("not working") } } cell.yes.tag = indexPath.row cell.yes.targetForAction("connected",withSender: self) println(cell.yes.tag) return cell}func connected(sender: UIbutton!) { var query = PFquery(classname:"Contacts") query.getobjectInBackgrounDWithID(objectIDs[sender.tag]) { (gamescore: PFObject!,error: NSError!) -> VoID in if error != nil { NSLog("%@",error) } else { gamescore["connected"] = "yes" gamescore.save() } }}解决方法 您需要添加该按钮的目标.
mybutton.addTarget(self,action: "connected:",forControlEvents: .touchUpInsIDe)
当然,您需要设置该按钮的标签,因为您正在使用该按钮.
mybutton.tag = indexPath.row
您可以通过将UItableVIEwCell进行子类化来实现此目的.在界面构建器中使用它,在该单元格上放一个按钮,通过插座连接到那里.
编辑:
要在连接的功能中获取标签:
func connected(sender: UIbutton){ let buttonTag = sender.tag}
EDIT2:
这个答案是针对swift 1.2提供的,正如评论中所提到的那样,swift 2.2的语法有所不同.
mybutton.addTarget(self,action: #selector(Classname.Functionname(_:),forControlEvents: .touchUpInsIDe)
EDIT3:
更新为Swift 3
mybutton.addTarget(self,action: #selector(Classname.Functionname.buttonTapped),for: .touchUpInsIDe)总结
以上是内存溢出为你收集整理的iOS Swift Button表格视图单元格中的动作全部内容,希望文章能够帮你解决iOS Swift Button表格视图单元格中的动作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)