UITableView 不加载数据 [英] UITableView does not load data

查看:35
本文介绍了UITableView 不加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 iOS 开发比较陌生.现在,我使用故事板创建了 2 个 ViewController.一个包含一个按钮,该按钮使用 segue(显示)通向另一个控制器.

I am relative new to iOS development. Right now, I created 2 ViewController using storyboard. The one consist one button that lead into another controller using segue (show).

这个控制器是TableViewController,它嵌入在Navigation Controller 中,并且已经与其从UITableViewController 继承的负责类相连.

This controller is TableViewController that embedded in Navigation Controller and already connected with its responsible class that inherit from UITableViewController.

我的问题是这个页面没有加载已经在 viewDidLoad 中使用

My problem is this page doesn't load its data (NSMutableArray) that already initialized in viewDidLoad using

_dataClient = [NSMutableArray arrayWithObjects:@"First City",@"Second City",@"Third City",@"Forth City",@"Fift City", nil];

这是我的表委托和数据源:

This is my table delegate and datasource:

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_dataClient count];
}

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

    // Configure the cell...
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    cell.textLabel.text = [_dataClient objectAtIndex:indexPath.row];

    return cell;
}

有什么我忘记做的步骤了吗?

Is there any step that I forgot to do?

推荐答案

必须至少返回 1 个部分.更改这一行:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1; /// here
}

这篇关于UITableView 不加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆