当我打印var array = [NSManagedObject]()
时,我在调试窗口中得到了[]
,并且我的tableview不会读取该数组。UITableView不读取阵列
我应该使用nsfetch还是从数组中读取数据?我设置了CoreData并且它可以工作,但是当我将数据发送到另一个vc并准备用于segue table view时,将不会读取var array = [NSManagedObject]()
。
其次VC又名实现代码如下:
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
}
}
你在哪里将数据加载到array中?在第一个vc中用var item = [NSManagedObject]()有 – Miknash
,有数据,并且我发送它的那个对象项准备继承var array = [NSManagedObject]()在第二个vc中,也就是tableview – Igy
这里是完整的项目http:/ /stackoverflow.com/questions/32863651/swift-2-0-core-data-tableview-not-reading-nsmanagedobject?noredirect=1#comment53566221_32863651 – Igy