ios - UITableView 不读取数组

标签 ios swift uitableview core-data

当我打印 var array = [NSManagedObject]() 时,我在调试窗口中得到 [],而我的 tableview 不会读取该数组。

我应该使用 nsfetch 还是什么来从那个数组中读取数据?我设置了 CoreData 并且它可以工作,但是当我将数据发送到另一个带有 prepare for segue table view 的 vc 时,不会读取 var array = [NSManagedObject]()

第二个 VC 又名 tableview:

import UIKit
import CoreData

class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!

var array = [NSManagedObject]()

override func viewDidLoad() {
    super.viewDidLoad()

   // self.array = self.bridge.item
    print(array)
    self.tableView.delegate = self
    self.tableView.dataSource = self


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
    return array.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

    let person = array[indexPath.row]
    cell.textLabel!.text = String(person)

    return cell
}

最佳答案

据我所知,问题不在于通过 segue 接收和发送数据。您发送正确,这就是您没有收到错误的原因。因此,问题出在您发送的数据中,发送时 NSManaged 对象的数组为空。我尝试以同样的方式发送,它正在工作。毫无疑问,如果您的数组包含数据,那么 TableView 不会读取数组,那么将创建的单元格数量等于您的数组元素的数量,现在它是空的。

关于ios - UITableView 不读取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32947400/

相关文章:

swift - : in Swift function signatures and why is there no comma when it seems there should be one?是什么意思

swift - UITableView 不在 UIView 容器内滚动

iphone - iPad 键盘不会从具有 Model View Controller 样式 UIModalPresentationFormSheet 的 View Controller 调用的 Facebook 对话框中关闭

ios - Alamofire 在接收所有数据之前验证 header (完整主体)

swift - 在 swift 中使用 switch 语句的 bool 函数

ios - 根据它使用的 UITableViewCell 类型更改 heightForRowAtIndexPath?

ios - 'RefreshControl' 上的“数组索引超出范围”

ios - CLLocationManager 未确定位置

iphone - 在mkmapview中获取路线的问题

ios 图表 LineChartView。如何选择图表的一部分