Search code examples
iosobjective-cuitableviewios5ios6

ios - why does my UITableView not get populated with comments


I have a UITableView which is declared like this in my .h file:

@interface EnterInviteCodeController : UIViewController
@property (weak, nonatomic) IBOutlet UITableView *itemList;
@end

And then I declare it like this in my .m file

#import "EnterInviteCodeController.h"

@interface EnterInviteCodeController ()
@property (nonatomic, retain) NSArray *items_array;
@end
@implementation EnterInviteCodeController
@synthesize itemList; // UITableView

But when I try to populate the list, no items show up. Here is how I populate the list. I make a remote call to a server to get the items. And then when the server comes back with data, I try to do this:

                         items_array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                         [self.itemList reloadData];

                         dispatch_sync(dispatch_get_main_queue(), ^{
                             [self.itemList reloadData];
                         });

But the data does not show up. Would anyone know what I am missing here?

Thanks!


Solution

  • Bare minimum you need to implement:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    

    and

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    and say you implement the UITableViewDataSource.

    @interface EnterInviteCodeController : UIViewController <UITableViewDataSource>
    

    Also make sure you set the File Owner as the delegate for your table.