ios – UITableViewCell accessoryView无法显示

前端之家收集整理的这篇文章主要介绍了ios – UITableViewCell accessoryView无法显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我完全不确定为什么我的配件视图不起作用.我只想在UITableViewCell(以及左侧)的右侧显示一些文本,但只显示左侧的文本. @H_403_2@- (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,60,30)]; cell.textLabel.text = @"left text"; label.text = @"right text"; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryView = label; [label release]; } return cell; }

有任何想法吗?谢谢.

解决方法

@H_403_2@cell.accessoryView = label;

您将accessoryView设置为标签,因此您不会看到任何披露指示.如果你想要你的单元格中的标题和详细文本,那么使用UITableViewCellStyleValue2像这样初始化它…

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

…然后像这样设置标题和细节……

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

要了解不同的内置表格样式,请查看以下图像…

您可以调整textLabel和detailTextLabel以适合您的口味.

猜你在找的iOS相关文章