切换回搜索栏活动时,标签栏视图变为空白 [英] Tab bar view goes blank when switched back to with search bar active

查看:22
本文介绍了切换回搜索栏活动时,标签栏视图变为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新 2:

因为人们仍在关注这个问题:知道我意识到不可能在实际的、独立的 iOS 设备上复制这个错误.当你展示搜索控制器时,iOS 也会展示一个键盘,它覆盖了标签栏.要切换标签页,您必须关闭键盘,这也会关闭搜索控制器.

Since people are still looking at this question: know that I realized it's impossible to replicate this bug on an actual, isolated iOS device. When you present the search controller, iOS presents a keyboard as well, which covers the tab bar. To switch tabs, you must dismiss the keyboard, which will dismiss the search controller as well.

我说孤立"的原因是因为我不知道您是否可以使用蓝牙键盘复制此功能并且没有尝试.iOS 键盘可能无法在连接了外部键盘的情况下显示

The reason I say "isolated" is because I don't know if you can replicate this with a Bluetooth keyboard and don't have one to try. The iOS keyboard might not be presented with an external keyboard connected

更新:

我向视图 1 添加了一个 viewWillDisappear 覆盖并发现了一些有趣的结果:

I added a viewWillDisappear override to View 1 and found some interesting results:

当搜索栏不存在时,切换标签会在加载下一个视图之前关闭视图.但是,当存在搜索栏时,在加载下一个视图之前不会关闭视图

When the searchbar is not present, switching tabs does dismiss the view before loading the next view. However, when the searchbar is present, the view is NOT dismissed before loading the next view

我在根目录有一个标签栏控制器,它有 2 个标签.每个都转到导航控制器,将设备带到视图.这是一个粗略的图表:

I have a tab bar controller at the root, which has 2 tabs. Each goes to a navigation controller that takes the device to the view. Here's a crude diagram:

                   /-> Navigation Controller -> View 1
tab bar controller 
                   \-> Navigation Controller -> View 2

这正常工作.但是,视图 1 有一个 UISearchController.错误在于,如果您单击搜索按钮,则会显示搜索控制器.如果然后单击选项卡栏中的 View 2 并切换回 View 1,则搜索控制器仍然存在并且视图为黑色.

This works fine normally. However, View 1 has a UISearchController. The bug is that if you click the search button, the search controller is presented. If you then click View 2 in the tab bar and switch back to View 1, the search controller is still there and the view is black.

我当前的hacky修复"是在搜索栏明显时禁用标签栏,如果用户选择取消"则重新启用它.这有两个问题:

My current hacky "fix" is to disable the tab bar while the search bar is apparent and re-enable it if the user selects "Cancel". This has 2 issues:

  1. 很卡;用户应该能够随时切换标签
  2. 它仅在用户点击取消"时重新启用,而不会在用户直接退出搜索时重新启用

我该如何解决这个问题?这是我正在谈论的图片

How can I fix this? Here are pictures of what I'm talking about

推荐答案

我按照以下答案解决了这个问题:UISearchController 导致黑屏 Swift 2.0

I solved this by following the answer at: UISearchController causes black screen Swift 2.0

我在 viewDidLoad 中是这样实现的:

I implemented it like so in viewDidLoad:

    self.definesPresentationContext = true

    searchController.searchResultsUpdater = self
    searchController.searchBar.delegate = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.definesPresentationContext = true

这几乎解决了我的问题.然后,我在尝试离开 didSelectRowAt 时遇到了另一个问题,这在以前从来都不是问题.我通过首先弹出 UISearchController,然后像往常一样执行 segue 来解决这个问题:

This pretty much solved the problem for me. Then I encountered another problem with trying to segue away at didSelectRowAt, which had previously never been an issue. I solved this by first popping the UISearchController, then performing a segue as normal:

_ = self.navigationController?.popViewController(animated: true)

这篇关于切换回搜索栏活动时,标签栏视图变为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆