gpt4 book ai didi

ios - 轻扫快速编辑sqlite数据库内容

转载 作者:可可西里 更新时间:2023-11-01 06:02:39 25 4
gpt4 key购买 nike

我正在尝试制作一个应用程序来存储可以删除的个人详细信息,使用 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" , handler: { (action:UITableViewRowAction, 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

// }

}

}

我想知道我哪里出错了。伙计们有什么想法吗?

提前致谢!

最佳答案

我遇到了完全相同的问题,我能够通过在 func prepareForSegue 中添加一些额外的东西来解决它

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

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

let cell = sender as! UITableViewCell
let Path = tableView.indexPathForCell(cell)
let index = Path?.row
let viewController : InsertRecordViewController = segue.destinationViewController as! InsertRecordViewController
viewController.isEdit = true
viewController.userData = self.marrUserData.objectAtIndex(index!) as! UserInfo

// }

}

现在我意识到这并不是您想要做的。因为使用我的方法,您只需单击单元格,它就会立即将您引导至路径,而不是滑动。我也想做幻灯片,但我想不出来,所以我只是用上面的方法。希望这会有所帮助:)

关于ios - 轻扫快速编辑sqlite数据库内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39033476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com