SDK iPhone Device 3.1 Разрывает вертикальное выравнивание textLabel UITableViewCellStyleValue1

StackOverflow https://stackoverflow.com/questions/1408105

  •  05-07-2019
  •  | 
  •  

Вопрос

Может ли кто-нибудь объяснить следующее явление?

Начиная с iPhone Device 3.1 SDK, я обнаружил, что если UITableViewCell имеет стиль UITableViewCellStyleValue1 и его detailTextLabel.text имеет вид в противном случае textLabel не будет отображаться в центре ячейки, как ожидалось.

Одна заметная оговорка заключается в том, что это происходит только для меня, когда я тестирую на устройстве & # 8211; iPhone Simulator 3.1 SDK правильно отображает ячейки. Кроме того, это не проблема при использовании iPhone Device 3.0 SDK.

Ниже приведена простая реализация подкласса UITableViewController , демонстрирующая проблему.

@implementation BuggyTableViewController

#pragma mark Table view methods


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

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

    switch (indexPath.row) {
  case 0:
   cell.textLabel.text = @"detailTextLabel.text unassigned";
   break;
  case 1:
   cell.textLabel.text = @"detailTextLabel.text = @\"\"";
   cell.detailTextLabel.text = @"";
   break;
  case 2:
   cell.textLabel.text = @"detailTextLabel.text = @\"A\"";
   cell.detailTextLabel.text = @"A";
   break;
  default:
   break;
 }

    return cell;
}

@end
Это было полезно?

Решение

вместо

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

попробуйте использовать

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

Другие советы

У меня тоже была такая же проблема. Ячейка выглядела отлично в симуляторе, но когда я запустил приложение на устройстве, текст ячейки не был центрирован вертикально. Использование UITableViewCellStyleDefault решило мои проблемы с центрированием вертикального выравнивания. К счастью, в моей камере нет субтитров.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top