And*_*y A 8 cocoa-touch uitableview accessoryview ios
我完全不确定为什么我的配件视图不起作用.我只是希望一些文本出现在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;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢.
Kir*_*odd 26
cell.accessoryView = label;
Run Code Online (Sandbox Code Playgroud)
您将accessoryView设置为标签,因此您不会看到任何披露指示.如果你想要你的单元格中的标题和详细文本,那么使用UITableViewCellStyleValue2像这样初始化它...
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cellType"] autorelease];
Run Code Online (Sandbox Code Playgroud)
...然后像这样设置标题和细节......
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Description";
Run Code Online (Sandbox Code Playgroud)
要了解不同的内置表格样式,请检查以下图像...

您可以调整textLabel和detailTextLabel以适合您的口味.
为什么这个?你不能两者兼得.
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21586 次 |
| 最近记录: |