2013-04-10 64 views
1

我有一个声明这样在我的.h文件一个UITableView填充:IOS为什么我的UITableView没有得到与评论

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

然后我宣布它像这样在我的.m文件

#import "EnterInviteCodeController.h" 

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

但是,当我尝试填充列表中,没有项目显示。这是我如何填充列表。我通过远程调用服务器来获取项目。然后,当服务器回来的数据,我试图这样做:

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

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

但数据不显示出来。有人会知道我在这里错过了什么吗?

谢谢!

回答

5

最低配置需要实现:

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

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

,说你实现UITableViewDataSource。

@interface EnterInviteCodeController : UIViewController <UITableViewDataSource> 

此外,请确保您将文件所有者设置为您的表的代表。

+0

谢谢!只是一个新手问题,那接口声明只能在.h文件中进行吗? – Genadinik 2013-04-10 15:45:18

+0

这一行“还要确保将文件所有者设置为您的表的代表。”有点混乱。你能否再详细解释一下。谢谢。 – Genadinik 2013-04-10 15:46:09

+0

是的,那只应该在头上。在界面生成器中,右键单击你的UITableView。你会看到它的网点。单击并拖动“委托”以指向文件所有者。 – kailoon 2013-04-10 15:47:34