Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reason 'uitable data source is not set' error in 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.

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
like image 308
pratik03 Avatar asked Oct 01 '14 07:10

pratik03


People also ask

What is data source in iOS?

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.

What is tableView delegate and datasource?

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..

What is table view delegate?

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.


1 Answers

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.

like image 74
pratik03 Avatar answered Sep 24 '22 10:09

pratik03