ios - why does my UITableView not get populated wi

2019-08-11 00:25发布

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!

1条回答
等我变得足够好
2楼-- · 2019-08-11 01:00

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.

查看更多
登录 后发表回答