0
votes

I have a UIViewController with one UITableView in it. The table view holds a list of favorites that can be changed by other parts of the app. I am using NSNotificationCenter to trigger the table view's reloadData method. The table view has an outlet declared as follows:

@property (strong,nonatomic) IBOutlet UITableView *faveTableView;

and synthesized as follows:

@synthesize faveTableView;

The delegate and datasource properties of the table view are set in the view controller's viewDidLoad as follows:

[self.faveTableView setDataSource:self];
[self.faveTableView setDelegate:self];

The NSNotificationCenter causes the following method to fire:

-(void)reloadNotificationReceived{
    [self loadData];
    [self.faveTableView reloadData];
}

loadData updates the data source which is NSMutableArray of managed objects and is working as it should.

When the view controller loads, cellForRowAtIndexPath is fired as it should be. However, when the notification is received, reloadNotificationReceived is fired and two of the table view delegate methods (numberOfRowsInSection and numberOfSectionsInTableView) ARE fired. However, cellForRowAtIndexPath is NOT fired. numberOfRowsInSection IS returning the correct number of items.

Can anyone offer up a reason why cellForRowAtIndexPath does not get fired here? Thanks!

2
Perhaps numberOfSectionsInTableView: returns one, and numberOfRowsInSection: returns zero? - Sergey Kalinichenko
Are you sure numberOfRowsInSection returns a count larger than 0? - Leo Natan
What is the number of rows you are returning? - Jeremy
If your table is not visible when the notification is sent, the runtime may skip updating the table altogether. Could that be the case in your app? - TotoroTotoro
Yes, numberOfRows is returning the correct number of items. I will edit the original post to reflect that - Pheepster

2 Answers

0
votes

The number of rows you are returning is 0.

0
votes

Perhaps you have set the delegate/datasource of the tableview to your controller in the storyboard/xib, but you haven't wired up the "faveTableView" tableview IBOutlet of the the controller... If the del/datasource are set, then the it will successfully get data from the controller, but without the IBOutlet being set, the self.faveTableView will remain nil and hence [self.faveTableView reloadData] won't do anything. Put a breakpoint in your viewDidLoad and check whether the self.faveTableView is not nil...