【问题标题】:Core Data Displaying Attributes Individually From Log核心数据从日志中单独显示属性
【发布时间】:2018-11-15 11:49:36
【问题描述】:

所以我一直在尝试将 Core Data 与记录信息的日志应用程序一起使用。在这种情况下,它是飞行时间。所以我输入数据,它使用核心数据来保存/存储是一个设定值,但我只让它在表格视图中显示少量保存的信息(见下面的代码)。

我需要帮助,所以我可以点击每个 tableViewCell 去一个 VC,它有用户输入到应用程序中的所有信息(因为它是一个日志)

如何才能让用户看到他们针对特定单元格的特定信息,这些单元格存储了不同的信息,因为它们都是不同的日志

    func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return logArray.count
}
//WHATS IN THE TABLE VIEW CELL FUNCTION/////
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 
    let log = logArray[indexPath.row]
    cell.textLabel!.text = "Flight:" + "  " + log.date! + "      Click For More Info -->"
    return cell
}

【问题讨论】:

    标签: swift uitableview core-data


    【解决方案1】:

    首先创建变量以登录您的UITableViewCell

    var log: Log?
    

    现在在cellForRowAt 中设置独立于indexPath.row 的单元格日志

    cell.log = logArray[indexPath.row]
    

    然后在第二个 ViewController 中创建变量。

    var selectedLog: Log?
    

    现在在表视图委托方法didSelectRowAtperform segue 与发件人作为该单元格

     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    self.performSegueWithIdentifier("yourIdentifier", sender: tableView.cellForRow(at: indexPath))
    }
    

    最后在准备 segue 方法中将目标 ViewController 声明为 YourSecondViewController 并设置其 selectedLogProperty

    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        if segue.identifier == "yourIdentifier" {
             let destinationVC = segue.destination as! YourSecond ViewController
             let senderCell = sender as! YourTableViewCell
             destinationVC.selectedLog = senderCell.log!
        }
    }
    

    【讨论】:

    • @RileyLunz :-) 如果有帮助,您可以接受我的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多