我想在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