And*_*ger 5 iphone uitableview
任何人都可以解释以下现象吗?
由于iPhone设备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
Run Code Online (Sandbox Code Playgroud)
代替
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
Run Code Online (Sandbox Code Playgroud)
尝试使用
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2318 次 |
| 最近记录: |