【发布时间】:2016-01-27 20:03:36
【问题描述】:
我对 iOS 开发比较陌生。现在,我使用情节提要创建了 2 个ViewController。一个包含一个按钮,该按钮使用 segue(显示)通向另一个控制器。
这个控制器是嵌入在导航控制器中的TableViewController,并且已经连接到它的负责类,该类继承自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;
}
有没有我忘记做的步骤?
【问题讨论】:
-
don'take -numberOfSectionsInTableView 方法默认为 1,如果您想要超过 1 个部分,那么您可以采用该方法并根据需要返回部分。
-
是的,我想我很少使用节超过一个的表,除了静态表。但是谢谢@bhavin ramani。
标签: ios objective-c iphone uitableview storyboard