您的位置:首页 > 产品设计 > UI/UE

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

2015-04-16 17:29 591 查看
这个方法是用来设置你的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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐