【问题标题】:Add "Plus" button for AccessoryType TableView为 AccessoryType TableView 添加“加号”按钮
【发布时间】:2011-06-11 08:34:26
【问题描述】:

我正在尝试实现一个 TableView,其中每个单元格都有一个“+”按钮,就像 iPod 应用程序在将歌曲添加到播放列表时一样。

cell.accesoryType 只有四个值

UITableViewCellAccessoryCheckmark

UITableViewCellAccessoryDetailDisclosureButton

UITableViewCellAccessoryDisclosureIndicator

None

如何做到这一点?我需要创建一个自定义按钮并设置cell.accessoryView 还是有其他方法可以做到这一点?

【问题讨论】:

    标签: iphone uitableview accessorytype


    【解决方案1】:

    Teo 的解决方案效果很好,但它没有作为答案发布,所以我重新发布它:

    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [button addTarget:self action:@selector(addbuttonTapped) forControlEvents:UIControlEventTouchUpInside];
    cell.accessoryView = button;
    

    【讨论】:

      【解决方案2】:

      JosephH 的一个简单变体,用于记忆。

      如果您只是想要一个装饰性的“+”按钮并继续使用原始的 didSelectRowAtIndexPath 触发器,请使用:

      UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
      [button setUserInteractionEnabled:NO];
      cell.accessoryView = button;
      

      通过禁用按钮上的用户交互,它将在底层视图上传播压力事件:单元格。

      【讨论】:

        【解决方案3】:

        如果您正在创建custom cell,则在其右上角放置一个button,就像accessory type 出现的位置一样,并将您的“+”图像分配给按钮,这样您也可以“看到图片”并获取“按钮动作事件”。

        请参阅 this 自定义 uitableviewcells 教程。

        【讨论】:

        • 找到解决方案 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [按钮 addTarget:self action:@selector(buttonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; cell.accessoryView = 按钮;并创建了事件处理过程 - (void)buttonTapped:(id)sender event:(id)event { }
        【解决方案4】:

        【讨论】:

        • 哦,是的,这可能是真的。我不明白他可能想编辑表格并向其中添加行,哪个苹果会给出绿色的“+”号?!
        猜你喜欢
        • 1970-01-01
        • 2013-12-19
        • 2016-02-23
        • 2013-05-10
        • 2015-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多