- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;方法意思

这个方法是用来设置你的TableView中每一行显示的内容和格式的。

indexPath 用来指示当前单元格,它的row方法可以获得这个单元格的行号,section方法可以获得这个单元格所处的区域号

static NSString *CellIdentifier = @"cell";//可复用单元格标识

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

NSInteger sectionNumber = [indexPath section];//分组的tableView里才有用

NSInteger rowNumber = [indexPath row];

cell.textLabel.text = [[myDataSource objectAtIndex:sectionNumber] objectAtIndex:rowNumber];//设置当前单元格的显示内容

cell.textLabel.textColor = [UIColor greenColor];//设置当前单元格的显示字体的颜色

}

return cell;

posted @ 2015-04-16 17:29  代佳宏  阅读(1357)  评论(0编辑  收藏  举报