Reputation: 41
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}>
Upvotes: 4
Views: 8022
Reputation: 773
I had the same symptoms too. In my case, the first time I loaded the data (from core data) in viewDidLoad, NSSortDescriptor was used to sort the data.
On the click of a button, the core data was fetched again (this time with changes) and tableView data reloaded. It initially gave me a blank table view after the button was clicked because I forgot to sort the data the second time I fetched it.
Learning points: Remember to call all methods which modify the cell like NSSortDescriptor if you have used them in the beginning!
Upvotes: 0
Reputation: 1
This may be too late, but anyways this might help.I have faced the same problem.
In short may be "Florian Segginger's" answer was right.
My situation was 1.calling web service asynchronously to get data (pull to refresh) 2.While this was processing, moved to another view controller (pushed) 3.poped back and my app crashed.
So in between steps 2 and 3, I noticed that number of rows and number of sections for table is actually called but cell for row did not.It resumed when I popped back by the time the count of the tablecell changed due to another logic.Handled this by testing, if view is visible in the connection did finish loading since I was reloading table in view will appear .This might be due to cell for row is actually a rendering(UI) action which should run on main thread.
Upvotes: 0
Reputation:
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...
Upvotes: 5
Reputation: 101
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]
Upvotes: 10
Reputation: 1
go to the header file of the viewcontroller and add (IBOutlet) to the tableView member. then connect throught interfaceb
Upvotes: 0