[英]UITableView does not load data
我是iOS开发的新手。 现在,我使用情节ViewController
创建了2个ViewController
。 一个按钮由一个按钮组成,该按钮使用segue进入另一个控制器(显示)。
该控制器是TableViewController
,它嵌入在Navigation Controller中,并且已经与其继承自UITableViewController
负责任的类连接。
我的问题是此页面不会使用viewDidLoad
中已初始化的数据加载其数据( NSMutableArray
)
_dataClient = [NSMutableArray arrayWithObjects:@"First City",@"Second City",@"Third City",@"Forth City",@"Fift City", nil];
这是我的表委托和数据源:
#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;
}
有什么我忘了要做的步骤吗?
您必须至少返回1个部分 。 更改此行:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; /// here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.