滚动时,带有自定义单元格xib的UITableView会崩溃EXC_BAD_INSTRUCTION

时间:2015-11-20 07:42:00

标签: ios iphone swift uitableview swift2

我有一个UITableView,它有来自xib文件的自定义单元格。前2个单元格显示正常(适合整个tableview)但是当我滚动并且我正在尝试自定义它的视图时,从cellForRowAtIndexPath传递的对象似乎是空的并且崩溃

在我的主要课程中:

//This is last version of fetchThemes, tried many stuff
        func fetchThemes() {
            let moc = AppDelegate().managedObjectContext
            let personFetch = NSFetchRequest(entityName: "Themes")
            personFetch.returnsObjectsAsFaults = false
            do {
                let fetchedPerson = try moc.executeFetchRequest(personFetch) as! [Themes]
                self.arr_themes.removeAll()
                for (var i = 0; i < fetchedPerson.count; i++){
                    arr_themes.append(fetchedPerson[i])
                }
                self.mytable.reloadData()

            } catch {
                fatalError("Failed to fetch person: \(error)")
            }
        }
        override func viewDidLoad() {
            super.viewDidLoad();
            self.fetchThemes()
            self.mytable.registerNib(UINib(nibName: "ThemeCell", bundle: nil), forCellReuseIdentifier: "section")
        }

            //MARK:- UITableView delegates

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

        }



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

            let currentTheme = self.arr_themes[indexPath.row] as Themes
            let cell = tableView.dequeueReusableCellWithIdentifier("section") as! ThemeCell
            cell.initCellUI(currentTheme)


            return cell;

    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath
        indexPath: NSIndexPath) -> CGFloat {
            return 224;
    }

自定义单元格xib中的崩溃:

enter image description here

发送到手机之前:

在发送之前,它看起来像这样,但实体对于此对象是空的

enter image description here

主题对象似乎是空的,我无法弄清楚原因。有什么建议吗?

0 个答案:

没有答案