The SimpleEKDemo sample has a "[self.tableView reloadData]" at the end of viewDidLoad in the RootViewController.m file.
Is this necessary? Any ideas why this line was put in? Wouldn't the view get drawn subsequently after the viewDidLoad via it's calls to the delegate to methods like "cellForRowAtIndexPath"?
- (void)viewDidLoad {
self.title = @"Events List";
// Initialize an event store object with the init method. Initilize the array for events.
self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];
// Get the default calendar from store.
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
// Create an Add button
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemAdd target:self action:@selector(addEvent:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
[addButtonItem release];
self.navigationController.delegate = self;
// Fetch today's event on selected calendar and put them into the eventsList array
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];
[self.tableView reloadData]; // ** REALLY NEEDED **
}
EDIT - I did note this in the doco (see below) - it's still not clear to me how the above line of code is required - isn't it the case that if you went to another view, and then back to this view, THEN if (a) the view is re-initialised than it would have to populate itself again anyway, or (b) if the view wan't re-initialised the "viewDidLoad" method wouldn't be called hence you wouldn't be putting the "reloadData" line of code at the end of the viewDidLoad method in either case no?
UITableView overrides the layoutSubviews method of UIView so that it calls reloadData only when you create a new instance of UITableView or when you assign a new data source. Reloading the table view clears current state, including the current selection. However, if you explicitly call reloadData, it clears this state and any subsequent direct or indirect call to layoutSubviews does not trigger a reload.