gpt4 book ai didi

ios - 在Swift中,如何从UITableView中获取对象id并根据对象id删除对象?

转载 作者:行者123 更新时间:2023-11-29 02:18:50 24 4
gpt4 key购买 nike

我不知道如何在用户选择后从 UITableView 中获取对象 ID,在另一个 View Controller 中,我想根据我已经从上一个 View 中获取的对象 ID 删除对象。

UITableView

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

/* grab object id here and pass to NSUserDefault*/

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let deleteViewController = storyBoard.instantiateViewControllerWithIdentifier("accessView") as DeleteViewController
self.presentViewController(deleteViewController, animated:true, completion:nil)

}

删除 View Controller

/* Delete object happen here*/

最佳答案

您可以在 DeleteViewController 中设置一个属性,并在初始化 View Controller 时将值传递给它。

class DeleteViewController {
var objectId: Int?
}

// Previous view controller
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

// Grab your object from the data source
let object = dataSource[indexPath.row]

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let deleteViewController = storyBoard.instantiateViewControllerWithIdentifier("accessView") as DeleteViewController

// Pass the Id
deleteViewController.objectId = object.objectId
self.presentViewController(deleteViewController, animated:true, completion:nil)


}

关于ios - 在Swift中,如何从UITableView中获取对象id并根据对象id删除对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28408810/

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