8

アクセサリビューが機能しない理由がまったくわかりません。UITableViewCellの右側(および左側)にテキストを表示したいのですが、左側のテキストのみが表示されています。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"SwitchCell"];

  if (cell==nil){
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"SwitchCell"] autorelease];
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 60, 30)];

      cell.textLabel.text = @"left text";
      label.text = @"right text";

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

      cell.accessoryView = label;
      [label release];

  }
  return cell;
}

何か案は?ありがとう。

4

5 に答える 5

26
cell.accessoryView = label;

開示インジケーターが表示されないように、accessoryView をラベルに設定しています。セルにタイトルと詳細テキストが必要な場合は、次のように UITableViewCellStyleValue2 で初期化します...

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellType"] autorelease];

...そして、このようにタイトルと詳細を設定します...

cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Description";

さまざまな組み込みのテーブル スタイルのアイデアを得るには、次の画像を確認してください...

ここに画像の説明を入力

好みに合わせて textLabel と detailTextLabel を調整できます。

于 2011-06-14T13:40:02.583 に答える
6

なぜこれ?両方を持つことはできません。

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
于 2011-06-14T13:23:50.413 に答える
3
-(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier

iOS 3.0 で減価償却されました

代わりに次を使用します。

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

UITableViewCellStyleValue1または のいずれかを渡し、必要に応じて プロパティとプロパティをUITableViewCellStyleValue2設定します。textLabeldetailTextLabel

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html%23//apple_ref/doc/uid/TP40006938-CH3-SW34

于 2011-06-14T13:32:47.977 に答える
0

UITableViewCellStyleValue2 は私に奇妙なスタイルを与えます。最も一般的に要求されるスタイルは UITableViewCellStyleValue1 だと思います (少なくとも私の場合)。

于 2015-04-19T11:12:48.540 に答える