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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6322798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:18:33  来源:igfitidea点击:

Adding the little arrow to the right side of a cell in an iPhone TableView Cell

iphoneobjective-cioscocoa-touchuitableview

提问by Eric Brotto

This should be simple enough.

这应该足够简单了。

I have an iPhone app with a TableView. How do I add the little classic arrow to the righthand side of each cell?

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

回答by EmptyStack

Just set the respective accessoryTypeproperty of UITableViewCell.

只需设置UITableViewCell的相应附件类型属性。

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

In Swift 3,

Swift 3 中

cell.accessoryType = .disclosureIndicator

回答by rzv

You can do this in Interface Builder. Simply click click on the Table View, go to Prototype Cellson the right side and make it 1. Then click that Prototype Celland on the right look for Accessory. In the drop-down, click Disclosure Indicator.

您可以在 Interface Builder 中执行此操作。只需单击Table View,转到右侧的Prototype Cells并将其设为1。然后单击该Prototype Cell并在右侧查找Accessory。在下拉列表中,单击披露指示器

Interface Builder example

界面生成器示例

回答by Lalit Kumar Maurya

You can set little classic arrow like two way as below

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

1) Using inbuilt accessory type method of UITableViewCell

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

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 

2) Creating own accessory view with own image

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

(I) Drag & drop an arrow image(i.e. circle_arrow_right.png) in your project

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

(II) In cell design method for every row as below

(二) 每一行的单元格设计方法如下

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

Write below code:

写下面的代码:

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
     .............
    .............

 }

[Note:Choose appropriate images for accessory view and add in your desired cells. Choose small images for accessory views for better performance.]

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

回答by Mridul Kashatria

Use the accessoryTypeproperty of the cell to show a arrow on the right side. See this.

使用accessoryType单元格的属性在右侧显示一个箭头。看到这个

回答by Ravi_Parmar

for simple arrow:

对于简单箭头:

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

and for detailed arrow:

和详细的箭头:

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

回答by Kyle Clegg

The other way to do this is to specify UITableViewCellAccessoryDisclosureIndicatorwhen you create the cell. To do this you'll likely alloc init your cell in the tableViewCellWithReuseIdentifier delegate method (then proceed to customize and configure your cell).

另一种方法是指定UITableViewCellAccessoryDisclosureIndicator何时创建单元格。为此,您可能会在 tableViewCellWithReuseIdentifier 委托方法中分配初始化您的单元格(然后继续自定义和配置您的单元格)。

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellAccessoryDisclosureIndicator reuseIdentifier:identifier];

回答by David Seek

Swift 3:

斯威夫特 3:

cell.accessoryType = .disclosureIndicator

回答by Uditha Prasad

Best way is select Disclosure Indicatorin Accessorysection.

最好的方法是Disclosure IndicatorAccessory部分中选择。