I have a simple application where I have a table view & depending on the callback with array I reload the table data using reloadData method. Initially for first 5-10 times of loading this table view works without any problem. After playing with the application for sometimes I noticed that the table view is blank because of the reason that cellForRowAtIndexPath is not called by the framework. I verified that datasource & delegate is set properly & numberOfRowsInSection is returning a valid positive number. Once I see the blank table view then I can see this blank view repeatedly until I exit the application. I do not get any error or warnings in the console. I tried to tweak the array but to no avail.
Here is the code:
- (void)notifyArrayLoaded:(NSArray *)arr {
NSUInteger capacity = [arr count];
_tbDataArray = [[NSMutableArray alloc] initWithCapacity:capacity];
// _tbDataArray is filled with the data from arr
// Reload the table data
[_tableView reloadData];
}
Any clue will be highly appreciated.
Thanks in advance. Sumit
Hi DeanWombourne, I do not have viewDidUnLoad method but I have viewWillDisAppear method which I am posting it here.
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
view.transform = CGAffineTransformIdentity;
view.transform = CGAffineTransformMakeRotation(0);
view.bounds = CGRectMake(0.0, 0.0, 320, 480);
}
This is the logs of tableView as logged.
[numberOfSectionsInTableView:] [Line 223] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
[tableView:numberOfRowsInSection:] [Line 229] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
<UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
[numberOfSectionsInTableView:] [Line 223] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
[tableView:numberOfRowsInSection:] [Line 229] <UITableView: 0xa5fc00; frame = (0 0; 320 0); clipsToBounds = YES; layer = <CALayer: 0x4830b0>; contentOffset: {0, 0}>
Make sure you call reloadData on the main thread. If you are loading your data asynchronously using performSelectorInBackground and calling reloadData in that method, you should, instead of doing something like:
[tableViewController reloadData]
What you should be doing is
[tableViewController performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]
If reloadData causes numberOfRowsInSection to be called but not cellForRowAtIndexPath, check that the UITableView instance you called reloadData on is the same UITableView that you have displayed in your view, e.g.
NSLog(@"Calling reloadData on %@", self.tableView);
[self.tableView reloadData];
I think you'll find you have two different UITableViews. The puzzle then is working out why...
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