在iPhone TableView Cell中将小箭头添加到单元格的右侧

Eri*_*tto 133 iphone cocoa-touch objective-c uitableview ios

这应该很简单.

我有一个带有TableView的iPhone应用程序.如何将小经典箭头添加到每个单元格的右侧?

Emp*_*ack 309

只需设置UITableViewCell的相应accessoryType属性即可.

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Run Code Online (Sandbox Code Playgroud)

Swift 3中,

cell.accessoryType = .disclosureIndicator
Run Code Online (Sandbox Code Playgroud)


rzv*_*rzv 62

您可以在Interface Builder中执行此操作.只需点击点击表视图,去原型细胞右侧,使其1.然后单击原型细胞和右边找配件.在下拉列表中,单击" Disclosure Indicator".

Interface Builder示例


小智 8

在 Swift 5 中

使用

cell.accessoryType = .detailButton
Run Code Online (Sandbox Code Playgroud)

右侧有一个小信息按钮。 在此输入图像描述

cell.accessoryType = .disclosureIndicator
Run Code Online (Sandbox Code Playgroud)

右侧有一个小信息箭头。 在此输入图像描述

cell.accessoryType = .detailDisclosureButton
Run Code Online (Sandbox Code Playgroud)

右侧有一个小信息按钮和信息箭头。 在此输入图像描述

在你的面前return cell


Lal*_*rya 6

您可以像下面两种方式设置小经典箭头

1)使用UITableViewCell的内置附件类型方法

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
Run Code Online (Sandbox Code Playgroud)

2)用自己的图像创建自己的附件视图

(I)在项目中拖放箭头图像(即circle_arrow_right.png)

(II)在每行的单元设计方法中如下

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
Run Code Online (Sandbox Code Playgroud)

写下面的代码:

if (cell ==nil) {
    cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier]autorelease];

    //For creating custom accessory view with own image
    UIImageView *accessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [accessoryView setImage:[UIImage imageNamed:@"circle_arrow_right.png"]];
    [cell setAccessoryView:accessoryView];
    [accessoryView release];

    //Your other components on cells
     .............
    .............

 }
Run Code Online (Sandbox Code Playgroud)

[ 注意:为附件视图选择合适的图像并添加所需的单元格.为附件视图选择小图像以获得更好的性能.]


Dav*_*eek 5

斯威夫特3:

cell.accessoryType = .disclosureIndicator
Run Code Online (Sandbox Code Playgroud)