Newbie 🙁
Tweaking my way through tutorials but 36 hours can’t figure this one
Example 1.h
@interface RootViewController : UITableViewController {
NSArray *userList; // the current list of users
}
@property (nonatomic, retain) NSArray *userList;
- (void) updateTable:(NSArray *)data;
- (void) fetchData;
@end
Example 1.m
- (void) updateTable:(NSArray *)data {
self.userList = data;
[self.tableView reloadData];
}
This works, the asynchronous XML object returns an array with the selector updateTable and the table updates.
But when I make the view a UIViewController the table doesn’t update
Example 2.h
@class xmlGetStories;
@interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
UITableView *tableView;
NSArray *userList;
}
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) NSArray *userList;
- (void) updateTable:(NSArray *)data;
- (void) fetchData;
@end
Example 2.m
- (void) updateTable:(NSArray *)data {
self.userList = data;
NSLog(@"updateTable sees this data: %@", userList);
//[self.tableView reloadData];
[tableView reloadData];
}
updateTable executes and the data is passed across alright but the table doesn’t refresh. I realise that it’s something to do with the way I’m addressing the table as it’s part of a UIViewController rather than a direct UITableViewController. But I thought that
UIViewController <UITableViewDataSource, UITableViewDelegate>
wired in the table. I have another testbed example where example two works if I hardcode the array contents into the AppDelegate.
I have tried
[FirstViewController reloadData];
[FirstViewController.tableView reloadData];
Neither work.
Brain dead looking at code. Hopefully it’s something simple.
TIA
The most likely cause is that
tableViewisnil. Make sure you have wired it in IB.