开发者

iphone code - custom table instead of default one

i'm using a default style table (UITableViewCellStyleSubtitle) i want to add more then one detailTextLabel in each row,

how can i customize it?

code:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                   reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

// Leave cells empty if there's no data yet
if (nodeCount > 0)
{
    // Set up the cell...
    ARecord *aRecord = [self.entries objectAtIndex:indexPath.row];

    cell.textLabel.text = aRecord.lDate;
    cell.detailTextLabel.text = aRecord.WNum;

    // Only load cached images; defer new downloads until scrolling ends
    //(!aRecord.appIcon) - use icon
    if (!aRecord.appIcon)
    {
        if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
        {
            [self startIconDownload:aRecord forIndexPath:indexPath];
        }
        // if a download is deferred or in progress, return a placeholder image
        cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];                
    }
    else
    {
        cell.imageView.image = aRecord.appIcon;
    }

}

return cell;
开发者_如何学Python

}


The best way of doing this is to add a UILabel to the cell.contentView. You would do this when you initially create the cell. I've found two things to be especially helpful: to lay out the label on a table cell in a throwaway document in Interface Builder to determine the initial frame. It's also especially helpful to set the autoresizingMask so that the label will be resized appropriately when the cell is resized (due to autorotation, going into edit mode, etc.).

Finally, you'll need to set the table view's rowHeight to a higher value to accommodate the larger cells, otherwise you'll end up with overlapping cells.

Also, set a tag on your label to make it easy to retrieve with viewWithTag: when you go to update the text.


You could add the labels to cell.contentView.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜