开发者

modifiy first row for each section of my tableview

i would modify the first row on each section (modify font size, color, aligment). I've think something like this:

    NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
    if (sectionRows == 0)开发者_Python百科{
    cell.textLabel.text = cellDetail;
    cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
    cell.detailTextLabel.backgroundColor = [UIColor blueColor];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    } else {
cell.textLabel.text = cellDetail;
cell.detailTextLabel.text = cellValue;
}

but this don't make the magic:D Please let me know if it's better to open another topic or we can continue here.


You can do this on-the-fly as the table is rendered. See UITableViewDelegate's -tableView:willDisplayCell:forRowAtIndexPath: method. This is invoked before the cell is drawn. You can make customizations to the cell here.

A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.


To get the row number of the indexPath, just use indexPath.row, and take it from there. So replace that first line with:

NSInteger sectionRows = [indexPath row];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜