Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义单元格xib的UITableView在滚动时崩溃EXC\u BAD\u指令_Ios_Iphone_Swift_Uitableview_Swift2 - Fatal编程技术网

Ios 自定义单元格xib的UITableView在滚动时崩溃EXC\u BAD\u指令

Ios 自定义单元格xib的UITableView在滚动时崩溃EXC\u BAD\u指令,ios,iphone,swift,uitableview,swift2,Ios,Iphone,Swift,Uitableview,Swift2,我有一个UITableView,它有来自xib文件的自定义单元格。前两个单元格显示正常(适合整个tableview),但当我滚动并尝试自定义其视图时,从cellforrowatinexpath传递的对象似乎为空并崩溃 在我的主课中: //This is last version of fetchThemes, tried many stuff func fetchThemes() { let moc = AppDelegate().managedObjec

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

在我的主课中:

//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;
    }
//这是fetchThemes的最后一个版本,尝试了很多东西
func fetchThemes(){
让moc=AppDelegate().managedObjectContext
让personFetch=NSFetchRequest(entityName:“主题”)
personFetch.returnsObjectsAsFaults=false
做{
let fetchedPerson=尝试moc.executeFetchRequest(personFetch)as![Themes]
self.arr_themes.removeAll()
对于(var i=0;iInt{
返回arr_.count;
}
func tableView(tableView:UITableView,
cellForRowAtIndexPath indexPath:NSIndexPath)->UITableViewCell{
让currentTheme=self.arr_themes[indexPath.row]作为主题
将cell=tableView.dequeueReusableCellWithIdentifier(“section”)设为!ThemeCell
cell.initCellUI(当前主题)
返回单元;
}
func tableView(tableView:UITableView,RowAtIndexPath的高度
indepath:nsindepath)->CGFloat{
返回224;
}
自定义单元格xib中的崩溃:

//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;
    }

发送到手机前:

//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;
    }
在发送之前,它看起来像这样,但该对象的实体为null


主题对象似乎是空的,我不明白为什么。有什么建议吗?

在将currentTheme变量传递到initCellUI方法之前检查它,它是空的?更新了我的答案。当前主题似乎有at实体,但当进入视图时,它有实体,所以它可能被取消分配或什么?!它位于var arr_themes=[themes]()内部,不应该阻止他释放吗?检查此链接,尝试使用[yourFetchrequest setReturnsObjectsAsFaults:NO]禁用故障;检查currentTheme变量,然后将其传递到initCellUI方法,它是空的?更新了我的答案。当前主题似乎有at实体,但当进入视图时,它有实体,所以它可能被取消分配或什么?!它位于var arr_themes=[themes]()内部,不应该阻止他释放吗?检查此链接,尝试使用[yourFetchrequest setReturnsObjectsAsFaults:NO]禁用故障;