Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need sample code for creating a custom image-based accessoryType in TableView

Here is the code I have for the tableview customizations.

How would I make the accessory indicator be an image (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;
}
like image 590
BC. Avatar asked Nov 14 '10 22:11

BC.


1 Answers

All you need is

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

Be careful though as in editing mode the cell property you need to update is called editingAccessoryView

like image 198
nicktmro Avatar answered Sep 27 '22 16:09

nicktmro