UINavigationController + UITableView + UISearchBar + UISplitViewController
我有一个烦人的问题。我的 UISplitViewController 的主(左)窗格中有一个 UINavigationController 和一个 UITableView。当我进行正常操作时,一切都会很好地推送到导航控制器上。
替代文本 http://files.droplr.com/files/8851942/WDO5y。 working.jpg
但是,当我进行搜索并推送内容时,它似乎没有考虑到导航栏所需的空间。它将新控制器推到了最顶部,然后放置了导航栏,与内容重叠!
替代文本 http://files.droplr.com/files/8851942/WDRem。 search.jpg
我应该添加它在纵向(在弹出菜单中)和 iPhone 上执行时效果很好。这是 UISplitViewController 的错误吗?
I have an annoying problem. I have an UINavigationController with an UITableView in the Master (Left) pane of my UISplitViewController. When I do normal operations, things push on on to the navigation controller fine.
alt text http://files.droplr.com/files/8851942/WDO5y.working.jpg
However, when I do a search and push things on, it's like it doesn't account for the space the navigation bar needs. It pushed the new controller on at the very top, then puts the navbar on, overlapping the content!
alt text http://files.droplr.com/files/8851942/WDRem.search.jpg
I should add it works fine when doing it in portrait (in the popup menu) and on the iphone. Is this an UISplitViewController bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我已经得到了你的答案 - [我也发布了链接问题的答案] -
以下是对我有用的步骤 [包含一些伪代码]:
1)既然你正在搜索,你肯定已经覆盖了
ShouldReloadForSearch
- 因此只需添加一段代码来保存/存储forSeachString
。2)这可能会根据您的应用程序而有所不同,但此步骤的要点是,如果没有加载搜索结果,您需要清除存储的搜索字符串[设置为空]。我在 UITableViewSource 中这样做了。我有 2 个构造函数 - 一个用于完整数据集,另一个用于过滤后的[搜索结果]数据集。所以我只是在完整数据集构造函数中将其设置为 null。是的,毫无疑问你可以用不同的方式来做,但我就是这么做的。
3) 接下来,按照最初的“答案”状态进行操作并调用 SetActive -
[self.searchDisplayController setActive:NO];
。他们主张重写 ViewDidAppear。我没有这样做...我在RowSelected
覆盖中推送下一个 UIViewController 后立即执行了此操作。4) 最后,在附加了 UISearchDisplayController 的 UIViewController 中 - 检查保存的搜索字符串,如果存在,则执行以下操作:1) 再次调用 SetActive,但这次使用 true 参数,即
setActive:YES
...然后 2) 将 searchBar 文本设置为您保存的搜索字符串值。我在ViewWillAppear
覆盖中执行了此操作。长话短说......这对我有用并且它保留了搜索结果。在步骤 4 中设置 searchBar 文本是关键...这有效地使过滤器持续存在。
希望这对某人有帮助
OK, I've got your answer- [I also posted this answer to the linked question]-
Here are the steps that worked for me [containing some pseudocode]:
1) Since you are searching you are most certainly already overriding
ShouldReloadForSearch
- So just add piece of code that saves/stores theforSeachString
.2) This one may vary quite a bit depending on your app- but the gist for this step is that you need to clear out the stored search string [set to null] if no search results are loaded. I did this in my UITableViewSource. I have 2 constructors- one for the full dataset and another on for the filtered [search results] dataset. So I just set it to null in my full dataset constructor. Yeah, you could do it differently no doubt but that's how I did it.
3) Next, do as the original "answer" states and call SetActive -
[self.searchDisplayController setActive:NO];
. They advocated doing it in override of ViewDidAppear. I didn't do that... I did this immediately after I pushed the next UIViewController in myRowSelected
override.4) Last, within your UIViewController that has the UISearchDisplayController attached- check for your saved search string and if it exists then do the following: 1) call SetActive again BUT this time with a true parameter ie
setActive:YES
... then 2) set the searchBar text to your saved search string value. I did this in theViewWillAppear
override.Long story short... this worked for me AND it maintains the search results. Setting the searchBar text in step 4 is the key... this effectively gets the filter to persist.
Hope this helps someone
我看到你一个多月前问过这个问题,不知道你是否找到了解决方案,但我遇到了同样的问题,并且搜索谷歌不断将我带到这个线程。我还没有测试它是否在设备上发生这种情况,因为我仍在等待我的设备发货,但它确实在模拟器中发生了这样的情况。我有一个根视图,它是带有搜索栏的 UITableViewController 子类,将任何内容推到导航堆栈上都会导致视图位于导航栏的顶部或后面,或者以某种方式正确的位置,但导航栏不可触摸。
我终于意识到,当视图通过覆盖 viewDidDisappear 或 viewWillDisappear 消失时,将搜索显示控制器设置为不活动,
[self.searchDisplayController setActive:NO];
。现在一切似乎都得到了正确的框架/边界,但是在弹出时您会丢失搜索显示。如果您愿意,我想您可以在离开时保存搜索显示的状态,然后在回来时将其返回。如果您找到了另一个解决方案,请告诉我。I see you asked this over a month ago, don't know if you ever found a solution for it but I have been running into the same issue and searching Google keeps bringing me to this thread. I haven't tested if it happens this way on the device as I am still waiting on mine to be shipped, but it did happen like this in the simulator. I have a root view that is a UITableViewController subclass with a search bar, pushing anything onto the navigation stack will result in the view either on top or behind the navigation bar, or somehow correct position but the navigation bar being untouchable.
It finally dawned on me to set the search display controller to not be active,
[self.searchDisplayController setActive:NO];
, when the view is disappearing by either overwriting the viewDidDisappear or the viewWillDisappear. Now everything seems to get the right frame/bounds, but you lose the search display when popping back. If you wanted to I guess you could save the state of the search display when leaving then return it when coming back. If you found a solution another solution let me know.