菜鸟教程小白 发表于 2022-12-11 17:08:34

ios - 快速单击导航栏按钮,导致 View 被多次推送


                                            <p><p>我正在使用 3 个 ViewControllerA、B、C。
在 Storyboard 中添加了从 A 到 B(例如 segue1)和 B 到 C(例如 segue2)的推送转场。
A 嵌入在导航 Controller 中。</p>

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

<p>如果我多次快速单击按钮, ViewB 会被推送一次,然后 ViewC 会被推送多次。</p>

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

<p>编辑:添加代码</p>

<p><strong>ViewController A:</strong></p>

<pre><code>- (void)viewDidLoad {
    ;

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

- (void)insertB:(id)sender {
    ;
}
</code></pre>

<p><strong> ViewControllerB:</strong></p>

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

- (void)insertC:(id)sender {
    ;
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>按下时将按钮的<code>userInteractionEnabled</code>属性设置为<code>false</code>,按下后将其更改为<code>true</code>。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 快速单击导航栏按钮,导致 View 被多次推送,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38696588/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38696588/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 快速单击导航栏按钮,导致 View 被多次推送