我完全不确定为什么我的配件视图不起作用。我只想在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;
}
有什么想法吗?感谢。
答案 0 :(得分:26)
cell.accessoryView = label;
您正在将您的accessoryView设置为标签,这样您就不会看到任何披露指示。如果你想要你的单元格中的标题和详细文本,那么使用UITableViewCellStyleValue2像这样初始化它...
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellType"] autorelease];
...然后像这样设置标题和细节......
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Description";
要了解不同的内置表格样式,请查看以下图片...
您可以根据自己的喜好调整textLabel和detailTextLabel。
答案 1 :(得分:6)
为什么这样?你不能兼得。
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
答案 2 :(得分:3)
-(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
在iOS 3.0中已弃用
改为使用:
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
传递UITableViewCellStyleValue1
或UITableViewCellStyleValue2
,并根据需要设置textLabel
和detailTextLabel
属性。
答案 3 :(得分:0)
UITableViewCellStyleValue2给了我一种奇怪的风格。我认为最常请求的样式是UITableViewCellStyleValue1(至少在我的情况下)。
答案 4 :(得分:0)
还要记住:如果您有自定义的accessoryView,则会忽略accessoryType属性。所以,这行代码是多余的。