【问题标题】:How to update button in UITableViewRowAction?如何更新 UITableViewRowAction 中的按钮?
【发布时间】:2016-01-22 10:35:34
【问题描述】:

我使用objective-c 编程iPhone App。版本在 iOS 8.1 之后。我的 UITableViewCell 中有一些 UITableViewRowAction,我在点击其中一个 UITableViewRowAction 后发布请求,如果成功,我希望将按钮 (UITableViewRowAction) 更新为无效,以便无法再次点击它。请帮助我,这很重要,但我没有解决方案。

如图: 这是我们可以向左滑动的单元格

向左滑动可以看到三个按钮

【问题讨论】:

  • 您需要为每个单元格手动维护一个状态。如果用户单击您的操作按钮,则保存该值。当用户再次滑动单元格时,只需更改该按钮的背景颜色,不要为此编写操作块。

标签: ios objective-c iphone uitableviewrowaction


【解决方案1】:

我认为你需要使用 UITableView 委托方法

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

【讨论】:

  • 按钮不是UITableViewCell添加的,是作为UITableViewRowAction添加的,向左滑动Cell后会看到
【解决方案2】:

使用didSelectRowAtIndexPath 方法发布您的请求。

在您的实施中:

{
int selectedIndex;
}

然后:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
       selectedIndex=indexPath.row;

        YourCell *cell = (YourCell *)[tableView cellForRowAtIndexPath:selectedIndex];
        if(cell.cellEnabled)
        {
        //Your request goes here...
        }
        else
       {
      //The cell is disabled..
        }
  }

cellEnabled 是在您的 cell.h 文件中声明的 BOOL 值,您必须在请求成功响应时将其设置为“YES”。

即;在获得成功响应后,添加以下代码

YourCell *cell = (YourCell *)[tableView cellForRowAtIndexPath:selectedIndex];
cell.cellEnabled=YES;

【讨论】:

  • 我不想让 UITableViewCell 无效,我只想让 button(UITableViewRowAction) 无效
  • 您说的是哪个按钮?它在单元格内吗?如果是,在获得成功响应后,添加以下代码。 YourCell *cell = (YourCell *)[tableView cellForRowAtIndexPath:selectedIndex];cell.button.enabled=NO;
  • 尽可能上传图片。
  • 我添加了两张图片,右边的按钮是我的目标
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-04
  • 2016-04-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2019-04-20
相关资源
最近更新 更多