ios - 访问核心数据以快速返回第一个单词

标签 ios swift xcode

我需要帮助删除核心数据中的一行

大纲:

我有一个 TableView ,它是从一个表单中填充的,该表单要求用户输入有关 friend 的详细信息。

用户需要一个从列表中删除好友的选项。当用户单击 TableView 中的一行时,我需要访问该字符串以获取 ID,然后查询该 ID 的核心数据,然后将其删除。

我坚持访问用户点击的数据并获取 ID

这是表格 View 中 friend 的样子

12345 James Bond 19 Male Sydney ICT

其中 12345 是唯一的学号

这是我从核心数据中删除 friend 的功能

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        tableView.delegate = self
        tableView.dataSource = self
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        friends = appDelegate.getFriendInfo()
        
        
        self.tableView.rowHeight = 33.0
        
    }
    
}

我在获取行内的 ID 然后从核心数据中删除该行时遇到困难

最佳答案

使用给定的 indexPath 从数组中检索 id

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let id = friends[indexPath.row].studentID
    let appDelegate = UIApplication.shared.delegate as! AppDelegate 
    appDelegate.removeRecord(id: id)
}

关于ios - 访问核心数据以快速返回第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64364792/

相关文章:

iOS Tap 手势状态开始不命中

Swift:在解包可选值时意外发现 nil (lldb)

swift - MacCatalyst 上未调用 didReceiveRemoteNotification

swift - NSUnknownKeyException - Xcode

iphone - scrollToRowAtIndexPath 不滚动到非事件/卸载的单元格

iphone - 为什么 UINavigationController 的 toolbarItems 在 View 的其余部分之后刷新 4-5 秒?

ios - 如何缩放 CALayer 以适应视频层

ios - 点击完成后如何隐藏标签?

iOS - iOS 8 中的 UIAlertView/UIAlertController 方向问题

objective-c - 如何将多种语言加载到 IVONA SDK - 文本到语音