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.
Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6048.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource is not set'
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
A data source object responds to data-related requests from the table. It also manages the table's data directly, or coordinates with other parts of your app to manage that data. Other responsibilities of the data source object include: Reporting the number of sections and rows in the table.
Datasource methods are used to generate tableView cells,header and footer before they are displaying.. Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..
func tableView(UITableView, willDisplay: UITableViewCell, forRowAt: IndexPath) Tells the delegate the table view is about to draw a cell for a particular row. func tableView(UITableView, indentationLevelForRowAt: IndexPath) -> Int. Asks the delegate to return the level of indentation for a row in a given section.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With