【发布时间】:2009-09-10 22:43:03
【问题描述】:
谁能解释以下现象?
从 iPhone Device 3.1 SDK 开始,我发现如果 UITableViewCell 的样式为 UITableViewCellStyleValue1 并且其 detailTextLabel.text 未分配,则 textLabel 不会显示在单元格的中心应该会。
一个值得注意的警告是,这只发生在我在 Device 上进行测试时——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
【问题讨论】:
-
这也是在 3.0 中,你应该在你知道会有一个 detailTextLabel 的单元格中设置具有该样式的分配单元格,如果没有,则设置为默认值。
-
我在 3.1.2 中也遇到了这个。完全相同:仅在设备上。我还注意到单元格中的标签在视图显示后使用动画移动到其不正确的位置。我拍了一部这样的电影,只是为了向自己证明我不是在想象它。使用 cell.detailTextLabel.text = @""; 的解决方法为我修好了。
标签: iphone uitableview