iPhoneデバイス3.1 SDKは、UITableViewCellStyleValue1 textLabelの垂直方向の配置を解除します
-
05-07-2019 - |
質問
次の現象について説明できる人はいますか
iPhone Device 3.1 SDKの時点で、 UITableViewCell
のスタイルが UITableViewCellStyleValue1
であり、その detailTextLabel.text
が割り当てられていない場合、 textLabel
は期待どおりセルの中央に表示されません。
注意すべき点の1つは、これはデバイスでテストしているときにのみ発生することです。 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を使用すると、垂直方向の配置の中央揃えの問題が解決しました。幸いなことに、私のセルにはサブタイトルがありません。
所属していません StackOverflow