UITableView 不加载数据
UITableView does not load data
我对 iOS 开发比较陌生。现在,我使用故事板创建了 2 ViewController
。一个包含一个按钮,该按钮使用 segue (show) 进入另一个控制器。
此控制器是 TableViewController
,嵌入在 Navigation Controller 中,并且已经连接到继承自 UITableViewController
的负责 class。
我的问题是此页面未加载其已在 viewDidLoad
中使用
初始化的数据 (NSMutableArray
)
_dataClient = [NSMutableArray arrayWithObjects:@"First City",@"Second City",@"Third City",@"Forth City",@"Fift City", nil];
这是我的 table 委托和数据源:
#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;
}
是否有任何步骤我忘记了?
您 必须 return 至少 1 个部分 。更改此行:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; /// here
}
我对 iOS 开发比较陌生。现在,我使用故事板创建了 2 ViewController
。一个包含一个按钮,该按钮使用 segue (show) 进入另一个控制器。
此控制器是 TableViewController
,嵌入在 Navigation Controller 中,并且已经连接到继承自 UITableViewController
的负责 class。
我的问题是此页面未加载其已在 viewDidLoad
中使用
NSMutableArray
)
_dataClient = [NSMutableArray arrayWithObjects:@"First City",@"Second City",@"Third City",@"Forth City",@"Fift City", nil];
这是我的 table 委托和数据源:
#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;
}
是否有任何步骤我忘记了?
您 必须 return 至少 1 个部分 。更改此行:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; /// here
}