iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在swift中滑动以编辑sqlite数据库内容大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图创建一个应用程序来存储可以删除的个人详细信息,使用editActionsForRowATindexPath进行编辑.删除选项似乎工作正常,但我遇到编辑操作的问题.

我得到了一个错误,如下所述:

Could not cast value of type 'Table_view.UserTableViewController' (0x10a1991b0) to 'NSIndexPath' (0x10a5e8438).

UserRecordViewController是View Controller,用于显示个人详细信息.而InsertRecordViewController是另一个View Controller.

UserTableViewController相关代码

func tableView(tableView: UITableView,editActionsForRowATindexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    // 1
    let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,title: "Edit",handler: { (action:UITableViewRowAction,indexPath:NSIndexPath) -> Void in

            self.performSegueWithIdentifier("editSegue",sender: self)

    })

    editAction.BACkgroundColor = UIColor.darkGrayColor()
   // let ediTindex = editAction.indexOfAccessibilityElement(indexPath.row)

    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,title: "delete",indexPath:NSIndexPath) -> Void in

        let userInfo: UserInfo = self.marrUserData.objectATindex(indexPath.row) as! UserInfo
        let isdeleted = ModelManager.geTinstance().deleteUserData(userInfo)
        if isdeleted {
            Util.invokeAlertMethod("",strBody: "Record deleted successfully.",delegate: nil)
        } else {
            Util.invokeAlertMethod("",strBody: "Error in deleting record.",delegate: nil)
        }
        self.getUserData()

    })

    deleteAction.BACkgroundColor = UIColor.lightGrayColor()

    return [deleteAction,editAction]
}



override func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) {

    if(segue.identifier == "editSegue"){

        let SELEctedIndexPath = sender as! NSIndexPath
        let index = SELEctedIndexPath.row
        //if let indexPath: NSIndexPath = self.tableView.indexPathForCell(sender as! UITableViewCell) {

        //let btnEdit : UIButton = sender as! UIButton
        //let SELEctedIndex : Int = btnEdit.tag
        let viewController : InsertRecordViewController = segue.desTinationViewController as! InsertRecordViewController
        viewController.isEdit = true
        viewController.userData = self.marrUserData.objectATindex(indeX) as! UserInfo

       // }

    }

}

我想知道我哪里出错了.伙计们好吗?

提前致谢!!

解决方法

导致错误的行是:let SELEctedIndexPath = sender as! NSIndexPath
Sender是SELEctedCell,而不是IndexPath!
在行self.performSegueWithIdentifier(“editSegue”,sender:self)之前,将类的属性(SELEctedIndexPath)设置为indexPath,然后从prepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?)访问此属性.

另一种方法可以在:https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson9.html#//apple_ref/doc/uid/TP40015214-CH9-SW1找到

大佬总结

以上是大佬教程为你收集整理的ios – 在swift中滑动以编辑sqlite数据库内容全部内容,希望文章能够帮你解决ios – 在swift中滑动以编辑sqlite数据库内容所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。