有人可以提供以下现象的解释吗?
从iPhone Device 3.1 SDK开始,我发现如果UITableViewCell
的样式为UITableViewCellStyleValue1
且未分配其detailTextLabel.text
,则textLabel
不会像预期的那样显示在单元格的中心。
一个值得注意的警告是,这仅在我在设备上测试时才发生– 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];
关于iPhone设备3.1 SDK破坏了UITableViewCellStyleValue1 textLabel的垂直对齐,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1408105/