开发者社区> 问答> 正文

在从viewController push新的tableViewController时,没有加载数据,是为何?

- (IBAction)openCardsTable:(id)sender {
    CardsTableViewController *controller = [[CardsTableViewController alloc]init];

    [self.navigationController pushViewController:controller animated:YES];
}

//CardsTableViewVontroller中
-(id)init{
    self = [super init];
    if(self){
        data = [ContactInfoStore defaultStore];
        NSLog(@"data array:%@",[data array]);
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    NSLog(@"data array:count:%lu",(unsigned long)[[data array] count]);
    return [[data array]count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];

    if(!cell){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellIdentifier"];
    }

    ContactInfo *item = [data.array objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:18.0];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13.0];
    cell.textLabel.text = item.name;
    cell.detailTextLabel.text = item.jobDescription;

    return cell;
}

展开
收起
a123456678 2016-07-28 11:00:44 1521 0
1 条回答
写回答
取消 提交回答
  • numberOfSectionsInTableView方法中return 1

    2019-07-17 20:01:14
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载