【问题标题】:Adding the little arrow to the right side of a cell in an iPhone TableView Cell在 iPhone TableView 单元格的单元格右侧添加小箭头
【发布时间】:2011-09-13 10:44:38
【问题描述】:

这应该很简单。

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

【问题讨论】:

    标签: iphone objective-c ios cocoa-touch uitableview


    【解决方案1】:

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

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    

    Swift 3 中,

    cell.accessoryType = .disclosureIndicator
    

    【讨论】:

    • 请注意,如果你想旋转箭头... 你不能这样做。您必须使用图像.. stackoverflow.com/questions/13836606/…
    • 对于 Swift 只需使用 cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
    • cell.accessoryType = .DisclosureIndicator 也适用于 Swift。
    • SWIFT 3.0:cell.accessoryType = .disclosureIndicator
    【解决方案2】:

    您可以在 Interface Builder 中执行此操作。只需点击Table View,转到右侧的Prototype Cells,将其设为1。然后点击Prototype Cell,然后在正确查找附件。在下拉菜单中,点击Disclosure Indicator

    【讨论】:

    • 我在我的 xCode 中看不到“原型单元格”之类的东西...它在某些版本的 xCode 中可用吗?
    • 我也找不到“原型单元”。我用过 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;在自定义单元格中。
    • 嘿@rzv 你能把图片放大一点吗?我忘记戴眼镜了
    【解决方案3】:

    你可以设置小经典箭头,如下两种方式

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

    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
    

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

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

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

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

    编写以下代码:

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

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

    【讨论】:

      【解决方案4】:

      使用单元格的accessoryType 属性在右侧显示一个箭头。见this

      【讨论】:

        【解决方案5】:

        对于简单的箭头:

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
        

        详细箭头:

        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        

        【讨论】:

        • cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator ;)
        【解决方案6】:

        斯威夫特 3:

        cell.accessoryType = .disclosureIndicator
        

        【讨论】:

          【解决方案7】:

          在 SWIFT 5 中

          使用

          cell.accessoryType = .detailButton
          

          右侧的小信息按钮。

          cell.accessoryType = .disclosureIndicator
          

          右侧的小信息箭头。

          cell.accessoryType = .detailDisclosureButton
          

          右侧有一个小的信息按钮和信息箭头。

          在你的return cell前面

          【讨论】:

            【解决方案8】:

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

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

            【讨论】:

              【解决方案9】:

              最好的方法是在Accessory 部分中选择Disclosure Indicator

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2020-09-07
                • 2020-10-20
                • 2019-08-06
                • 1970-01-01
                • 1970-01-01
                • 2023-03-08
                • 2016-03-16
                • 1970-01-01
                相关资源
                最近更新 更多