iPhone Device 3.1 SDK中断UITableViewCellStyleValue1 textLabel的垂直对齐方式

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

  •  05-07-2019
  •  | 
  •  

任何人都可以解释以下现象吗?

从iPhone Device 3.1 SDK开始,我发现如果 UITableViewCell 的样式为 UITableViewCellStyleValue1 ,其 detailTextLabel.text 为未分配,然后 textLabel 不会像预期的那样显示在单元格的中心。

一个值得注意的警告是,当我在设备–上测试时,这种情况只会发生在我身上。 iPhone 模拟器 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