菜鸟教程小白 发表于 2022-12-12 12:55:55

ios - 禁用表格 View 滚动


                                            <p><p>问题来了:</p>

<p>我在现有的 tableviewControllerE 之上展示了一个 popover tableviewControllerP。</p>

<p>我遇到的问题是 E 仍然滚动。这意味着如果您滚动到 P 的范围之外,E 将滚动并且 P 将表现得好像它是 E 的一部分。</p>

<p>如何在显示 P 时禁用 E 滚动?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>当你呈现 P 时,设置:</p>

<p><code>yourTableView.isScrollEnabled = false</code></p>

<p>当你关闭你的弹出框时:</p>

<p><code>yourTableView.isScrollEnabled = true</code></p>

<p><strong>注意:当您关闭弹出框时,您可能希望使用协议(protocol)再次启用滚动。</strong></p>

<p>为此,我将在您的弹出 ViewController 中添加:</p>

<pre><code>protocol ProtocolPopOver{
func enableScrollAgain();
}
</code></pre>

<p>然后,在那个 ViewController 中:</p>

<pre><code>var delegatePopOver:ProtoclPopOver?
</code></pre>

<p>当你关闭你的 viewController 时:</p>

<pre><code>self.dismiss(animated: true, completion: { delegatePopOver.enableScrollAgain() })
</code></pre>

<p>在您的主视图 Controller 中,当您呈现弹出框时,添加:</p>

<pre><code>popoverViewController.delegatePopOver = self
</code></pre>

<p>在 UIViewController 附近实现协议(protocol):</p>

<pre><code>class yourclass: UIViewController, ProtocolPopOver{...
</code></pre>

<p>并添加功能:</p>

<pre><code>func enableScrollAgain(){
yourTableView.isScrollEnable = true
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 禁用表格 View 滚动,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42280529/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42280529/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 禁用表格 View 滚动