Как отцентровать текст в UITableViewCell, если для аксессуара задано значение UITableViewCellAccessoryCheckmark

Я пытаюсь удерживать текст по центру в UITableViewCell, когда у меня для аксессуара установлено значение UITableViewCellAccessoryCheckmark. Я также использую раскадровку с этим классом.

Вот скриншот того, чего я не хочу.

Как предотвратить отступ текста влево?

enter image description here

Мой метод willDisplayCell..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == [self cellToCheckmark]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        NSLog(@"Not Being Checked");
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

cell.textLabel.textAlignment = UITextAlignmentCenter;

    if (cell.shouldIndentWhileEditing == YES) {
        cell.shouldIndentWhileEditing = NO;
    }
}

CellForRowAtIndexPath:

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

    UITableViewCell *cell = nil;

    static NSString *CellIdentifier = @"Cell";
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.textAlignment = UITextAlignmentCenter;

    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                cell.textLabel.text = @"Google";
                break;

            case 1:
                cell.textLabel.text = @"Bing";
                break;

            case 2:
                cell.textLabel.text = @"Yahoo!";
                break;

            default:
                break;
        }
    }

    if (indexPath.row == [self cellToCheckmark]) {
        NSLog(@"Being Checked");
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        NSLog(@"Not Being Checked");
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    if (cell.shouldIndentWhileEditing == YES) {
        cell.shouldIndentWhileEditing = NO;
    }   
    return cell;
}
5
задан W Dyson 1 June 2012 в 15:56
поделиться