UITableViewCell аксессуар ViewView не отображается - PullRequest
8 голосов
/ 14 июня 2011

Я совершенно не уверен, почему мой вспомогательный вид не работает. Я просто хочу, чтобы какой-то текст отображался справа от 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;
}

Есть идеи? Спасибо.

Ответы [ 5 ]

26 голосов
/ 14 июня 2011
cell.accessoryView = label;

Вы устанавливаете ваш accessoryView как ярлык, поэтому вы не увидите индикатор раскрытия. Если вам нужен заголовок и подробный текст в вашей ячейке, тогда начните его с UITableViewCellStyleValue2, как это ...

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

... а затем установите заголовок и детали, как это ...

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

Чтобы получить представление о различных встроенных стилях таблиц, проверьте следующее изображение ...

enter image description here

Вы можете настроить textLabel и detailTextLabel на свой вкус.

6 голосов
/ 14 июня 2011

Почему это? Вы не можете иметь оба.

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
3 голосов
/ 14 июня 2011
-(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier

устарела в iOS 3.0

Вместо этого используйте:

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

Передайте UITableViewCellStyleValue1 или UITableViewCellStyleValue2 и установите свойства textLabel и detailTextLabel, как вам нужно.

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

0 голосов
/ 08 июня 2017

Также помните: свойство accessoryType игнорируется, если у вас есть собственный accessoryView.Итак, эта строка кода избыточна.

0 голосов
/ 19 апреля 2015

UITableViewCellStyleValue2 дает мне странный стиль. Я думаю, что наиболее часто запрашиваемый стиль - это UITableViewCellStyleValue1 (по крайней мере, для моего случая).

...