但我一直收到错误“无法识别的选择器发送到实例”
这是我用于在cellForRowAtIndexPath函数中设置gestureRecognizer的代码:
overrIDe func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell { let cell = tableVIEw.dequeueReusableCellWithIDentifIEr("cell",forIndexPath: indexPath) as UItableVIEwCell; cell.textLabel!.text = tableArray[indexPath.row]; let holdToDelete = UILongPressGestureRecognizer(target: cell,action: "longPressDelete"); holdToDelete.minimumPressDuration = 1.00; cell.addGestureRecognizer(holdToDelete); return cell;}
这是longPressDelete函数:
func longPressDelete(sender: UILongPressGestureRecognizer) { let alert: UIAlertController = UIAlertController(Title: "Please Confirm",message: "Are you sure you want to delete this car from your database?",preferredStyle: .Alert); alert.addAction(UIAlertAction(Title: "Yes",style: .Destructive,handler: { (UIAlertAction) -> VoID in if let tv = self.tableVIEw { let point: CGPoint = sender.locationInVIEw(self.tableVIEw); let indexPath: NSIndexPath = self.tableVIEw.indexPathForRowAtPoint(point)!; tv.deleteRowsAtIndexPaths([indexPath],withRowAnimation: .Fade); NSUserDefaults.standardUserDefaults().removeObjectForKey("fillUp" + tableArray[indexPath.row]); NSUserDefaults.standardUserDefaults().removeObjectForKey("services" + tableArray[indexPath.row]); tableArray.removeAtIndex(indexPath.row); NSUserDefaults.standardUserDefaults().setobject(tableArray,forKey: "cars"); self.deleted = true; self.performSegueWithIDentifIEr("tableToDashboard",sender: self); } })); alert.addAction(UIAlertAction(Title: "No",style: .Default,handler: nil)); self.presentVIEwController(alert,animated: true,completion: nil);}
这是prepareForSegue函数:
overrIDe func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) { if (deleted) { let indexPath: NSIndexPath = NSIndexPath(forRow: 0,inSection: 0); fillUpKey = "fillUp" + tableArray[indexPath.row]; servicesKey = "services" + tableArray[indexPath.row]; localFillUpArray = [fillUp](); } else { let indexPath: NSIndexPath = self.tableVIEw.indexPathForSelectedRow!; fillUpKey = "fillUp" + tableArray[indexPath.row]; servicesKey = "services" + tableArray[indexPath.row]; localFillUpArray = [fillUp](); }}
我想要发生的是用户删除单元格中的项目,然后应用程序在从其他来源加载信息后执行到前面屏幕的segue.感谢您花时间阅读本文并提供答案.我希望我没有在某个地方犯过新手的错误.
解决方法 选择器不正确let holdToDelete = UILongPressGestureRecognizer(target: self,action: "longPressDelete:");
>:在longPressDelete之后指示方法func longPressDelete(sender:UILongPressGestureRecognizer)实际上接受参数.
> self for target,假设选择器属于注册它的同一个类.
当前选择器“longPressDelete”将匹配没有参数的方法签名:
func longPressDelete() { }总结
以上是内存溢出为你收集整理的ios – 长按删除tableViewCell全部内容,希望文章能够帮你解决ios – 长按删除tableViewCell所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)