我完全不确定为什么我的附件视图不能工作。我只想让一些文本显示在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;
}有什么想法吗?谢谢。
发布于 2011-06-14 21:40:03
cell.accessoryView = label;您正在将您的accessoryView设置为一个标签,因此您将不会看到任何披露指示器。如果你想在你的单元格中包含标题和细节文本,那么就像这样用UITableViewCellStyleValue2来初始化它…
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellType"] autorelease];然后...and像这样设置标题和细节...
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Description";要了解不同的内置表样式,请查看下图...

您可以根据自己的喜好调整textLabel和detailTextLabel。
发布于 2011-06-14 21:23:50
为什么是这个?你不能两者兼得。
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;发布于 2011-06-14 21:32:48
-(id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier请改用:
-(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
https://stackoverflow.com/questions/6344105
复制相似问题