我想在UITableView中添加数据源。我尝试以下,但遗憾的是它没有工作:UITableView和数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 8;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Set the data for this cell:
cell.textLabel.text = [_classCellview objectAtIndex:indexPath.row];
cell.detailTextLabel.text = @"One";
cell.detailTextLabel.text = @"Two";
// set the accessory view:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
是否调用了cellForRowAtIndexPath? – SG1 2013-04-04 21:08:26
你是什么意思的“没有工作”? – tilo 2013-04-04 21:08:49
我看不到'tableView:numberOfRowsInSection:'的实现,'UITableViewDataSource'是必需的。你可以张贴吗? – MishieMoo 2013-04-04 21:13:59