【问题标题】:Rapidly clicking a navigation bar button, results in a view getting pushed multiple times快速单击导航栏按钮,导致视图被多次推送
【发布时间】:2016-12-06 09:36:47
【问题描述】:

我正在使用 3 个视图控制器 A、B、C。 在情节提要中添加了从 A 到 B(例如 segue1)和 B 到 C(例如 segue2)的推送转场。 A 嵌入在导航控制器中。

在 A 中,我添加了一个右栏按钮并对其操作执行 segue1。 同样在 B 中,我正在添加另一个右栏按钮并对其操作执行 segue2。

如果我多次快速单击按钮,视图 B 会被推送一次,然后视图 C 会被推送多次。

这是一个已知问题吗?或者我的实现有什么问题吗?

编辑:添加代码

ViewController A:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertB:)];
    self.navigationItem.rightBarButtonItem = addButton;
}

- (void)insertB:(id)sender {
    [self performSegueWithIdentifier:@"segue1" sender:sender];
}

视图控制器 B:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertC:)];
    self.navigationItem.rightBarButtonItem = addButton;
}

- (void)insertC:(id)sender {
    [self performSegueWithIdentifier:@"segue2" sender:sender];
}

【问题讨论】:

  • 显示一些代码,看看你的实现是否有问题

标签: ios objective-c uinavigationcontroller uibarbuttonitem uistoryboardsegue


【解决方案1】:

按下时将按钮的userInteractionEnabled属性设置为false,按下后将其更改为true

【讨论】:

  • 在这种类型的实现中是否总是需要这样做?
  • 没有。但可能是应用程序发出的请求在进入下一个视图之前需要一些时间,这允许在进度结束之前多次按下按钮。你能显示一些代码吗?
  • 没有应用程序没有发出任何请求,我在一个非常简单的项目上进行了测试,没有其他代码。请检查有问题的添加代码
猜你喜欢
  • 1970-01-01
  • 2016-06-21
  • 1970-01-01
  • 2016-01-30
  • 2019-11-23
  • 1970-01-01
  • 1970-01-01
  • 2011-11-25
  • 1970-01-01
相关资源
最近更新 更多