- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;方法意思
时间:
2015-04-16 19:08:46
阅读:
433
评论:
收藏:
0
[点我收藏+]
这个方法是用来设置你的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;- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;方法意思
原文:http://www.cnblogs.com/daijiahong/p/4432727.html