iOS 8.0.2 中“未设置合适的数据源"错误的原因 [英] reason 'uitable data source is not set' error in iOS 8.0.2

查看:23
本文介绍了iOS 8.0.2 中“未设置合适的数据源"错误的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,该视图具有用于显示联系人列表的表格和另一个用于显示其详细信息的视图.问题是当我打开联系人视图时,它工作正常;但是当我打开它时,转到联系人的详细信息视图并按回,然后它就会崩溃.它向我显示如下错误.

I have a view having table to display list of contacts and another view for its detail. Issue is when I open contacts-view then it works fine; but when i open it, go to detail view of contact and press back then it gets crashes. It shows me error like below.

断言失败 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]、/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6048.
由于未捕获的异常NSInternalInconsistencyException"而终止应用,原因:UITableView 数据源未设置"

我在 iOS 8.0.2 中观察到了这一点,它在 iOS 7.0 上运行良好.有没有与iOS版本相关的东西?

I have observed this in iOS 8.0.2 which works fine on iOS 7.0. Is there anything related to iOS version.?

同样的事情发生在消息模块中.我在这里发布代码片段.

Same thing is happening in Message module. Here I am posting code snippet.

MessageListController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];

    self.tabBarController.tabBar.hidden = FALSE;

    instanceMessageList.delegate = self;
    instanceMessageList.dataSource = self;
    [self setNavigationBarView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self setEditing:FALSE animated:YES];
}

- (void)dealloc
{
    [instanceMessageList release];
    [super dealloc];
}

MessageListViewController.h

@interface MessageListViewController : UIViewController <UITableViewDelegate, UITableViewDataSource,NSFetchedResultsControllerDelegate, MessageDelegate, UIActionSheetDelegate>
{
#pragma mark -
#pragma mark Instance variable declaration

    IBOutlet UITableView *instanceMessageList;
    IBOutlet UILabel *noMessages;
}

#pragma mark -
#pragma mark Instance variable property declaration

@property (nonatomic, retain) UITableView *instanceMessageList;

@end

推荐答案

得到了解决方案.实际错误不在上面的代码中.viewWillDisappear() 方法中的详细视图发生错误.
根本原因是:按下后退按钮时,键盘被隐藏,这导致 UITableView 执行 CellForRowAtIndexPath() 方法,当时和在 ViewWillDisappear() 方法中我正在设置表的数据源为零.导致错误.

Got the solution. Actual error is not here in above code. Error occurs in detail view in viewWillDisappear() method.
Root cause is: when back button is pressed, keyboard is hidden which causes UITableView to execute CellForRowAtIndexPath() method and at that time and in ViewWillDisappear() method I was setting table's datasource to nil. which caused error.

这篇关于iOS 8.0.2 中“未设置合适的数据源"错误的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆