Cocoa touch UITableView色块

Cocoa touch UITableView色块,cocoa-touch,uitableview,uikit,nsmutablearray,Cocoa Touch,Uitableview,Uikit,Nsmutablearray,我需要创建一个UITableView(iOS开发),它将在每个表格单元格项旁边显示一个彩色块 假设我有一个NSMutableArray对象,其中包含一个名为itemColor的值,当我填充表格时,如何在包含itemColor的单元格旁边显示颜色块 基本上,我需要一个自定义的UITableView类似于Twitter显示头像的方式?我在我的项目中有类似的要求。 这肯定会对你有帮助 -(UITableViewCell *)tableView:(UITableView *)tableView cell

我需要创建一个
UITableView
(iOS开发),它将在每个表格单元格项旁边显示一个彩色块

假设我有一个
NSMutableArray
对象,其中包含一个名为
itemColor
的值,当我填充表格时,如何在包含itemColor的单元格旁边显示颜色块


基本上,我需要一个自定义的
UITableView
类似于Twitter显示头像的方式?

我在我的项目中有类似的要求。 这肯定会对你有帮助

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier;
    UITableViewCell *cell;
    cellIdentifier = [NSString stringWithFormat:@"Cell Identifier"];

    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil) {
        cell = [self tableViewCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 
    }
    [self configureCell:cell forIndexPath:indexPath];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


-(UITableViewCell *)tableViewCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath{
    CGRect rect;
    UILabel *label;
    UIView *backView;
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];

    float center = (float) (CELL_HEIGHT-MAINFONT_SIZE)/2;

    rect = CGRectMake(15, center, 150, MAINFONT_SIZE);
    label = [[UILabel alloc] initWithFrame:rect]; 
    label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    label.tag = NAME_ID_TAG;
    label.font = [UIFont boldSystemFontOfSize:MAINFONT_SIZE];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor blackColor];
    //label.highlightedTextColor = [UIColor whiteColor];
    [cell.contentView addSubview:label];
    [label release];

    rect = CGRectMake(160, 10, 150, CELL_HEIGHT-20);
    backView = [[UIView alloc] initWithFrame:rect];
    backView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |     UIViewAutoresizingFlexibleWidth;
    backView.backgroundColor = [UIColor clearColor];
    backView.tag = BACK_VIEW_TAG;



    [cell.contentView addSubview:backView];
    [backView release];

    return cell;
}



-(void)configureCell:(UITableViewCell *)tableViewCell forIndexPath:(NSIndexPath *)indexPath{
    //DeviceInfo *device;
    UILabel *label;
    PatientInfo *patInfo;
    UIView *backView;
    patInfo = [patientarray objectAtIndex:indexPath.row];

    label = (UILabel *)[tableViewCell viewWithTag:NAME_ID_TAG];
    label.text = patInfo.patientName;

    backView = (UIView *)[tableViewCell viewWithTag:BACK_VIEW_TAG];


       backView.backgroundColor = UIColorFromRGB(patInfo.itemColor);


}

据我所知,这太完美了!我对可可和其他东西还是有点陌生,所以你有没有一个小例子可以让我看看?对于我来说,仅仅获得正确的设置是一件困难的事情。参见本教程,您将了解在TableView上显示数据的基本概念。然后查找上面的代码。完美的非常感谢:)很快,我如何从
pList
中执行此操作,它包含数组中的数组?与您提供的链接类似,但具有额外的嵌套级别。