我需要示例代码在TableView中创建基于图像的自定义accessoryType

时间:2010-11-14 22:33:57

标签: iphone uitableview accessorytype

以下是我对tableview自定义的代码。

如何使附件指示器成为图像(arrow.png)

-(UITableViewCell *)tableView : (UITableView *)tableView 
        cellForRowAtIndexPath : (NSIndexPath *)indexPath {

    static NSString * CellIdentifier = @ "Cell";

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                       reuseIdentifier:CellIdentifier] autorelease];

        // Code to wrap the text within the cell for larger text
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@ "Helvetica" size:17.0];
        UIImageView * separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@ "separator.png"]];
        separator.frame = CGRectMake((cell.frame.size.width - separator.frame.size.width) / 2, 
                                     CELL_HEIGHT - separator.frame.size.height, 
                                     separator.frame.size.width, 
                                     separator.frame.size.height);
        [cell addSubview : separator];
        [separator release];
    }

    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.text = [titleList objectAtIndex:indexPath.row];

    // display the disclosure button
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

1 个答案:

答案 0 :(得分:5)

你需要的只是

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
    cell.accessoryView = imageView;

请注意,在编辑模式下,您需要更新的单元格属性称为editingAccessoryView