Мне нужен пример кода для создания собственного accessoryType на основе изображений в TableView - PullRequest
4 голосов
/ 15 ноября 2010

Вот код, который у меня есть для настроек вида таблицы.

Как бы я сделал индикатор аксессуара изображением (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 Ответ

5 голосов
/ 15 ноября 2010

Все, что вам нужно, это

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

Будьте осторожны, хотя, как и в режиме редактирования, свойство ячейки, которое нужно обновить, называется editingAccessoryView

...