所以我一直在尝试将 Core Data 与记录信息的日志应用程序一起使用。在这种情况下,它是飞行时间。因此,我输入数据,它使用核心数据来保存/存储作为设置值,但我只让它在 TableView 中显示少量保存的信息(请参见下面的代码)。
我需要帮助,它使得我可以单击每个 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
}
最佳答案
首先创建用于登录 UITableViewCell
的变量
var log: Log?
现在在cellForRowAt
中设置独立于indexPath.row
的单元格日志
cell.log = logArray[indexPath.row]
然后在第二个 ViewController 中创建变量。
var selectedLog: Log?
现在在 TableView 委托(delegate)方法中didSelectRowAt
将发送者作为该单元格执行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!
}
}
关于swift - 核心数据从日志中单独显示属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53318845/