如何从 UITabBar 控制器内的控制器使用 UISearchDisplayController?

发布于 2024-07-30 05:27:55 字数 425 浏览 6 评论 0原文

我有一个 UITabBar 控制器管理多个控制器(使用 SDK 3.0)。 其中之一是 tableView 控制器,我需要使用 UISearchDisplayController 提供搜索功能。 我的所有代码都是基于 Apple TableSearch 示例。 但是,当单击选项卡时,会出现 tableView 控制器,显示其相关内容,但不会出现 searchBar。 我已经检查了 IB 中的 xib 以确保所有插座均已正确设置,但无论我尝试什么, self.searchDisplayController 始终为零并且搜索栏不会出现。

在实践中,我从 TableSearch 示例中复制了 MainView.xib,并将文件的所有者类设置为选项卡的正确控制器类。 出口的设置如示例 MainView.xib 中所示。 我是否错过了任何重要步骤或做错了什么?

先感谢您。

I have an UITabBar controller managing several controllers (using SDK 3.0). One of these is a tableView controller and I need to provide a search capability using the UISearchDisplayController. All of my code is based on Apple TableSearch example. However, when clicking on the tab, the tableView controller appears showing its related content, but no searchBar appears. I have checked the xib in IB to make sure that all of the outlets are properly set, but no matter what I try self.searchDisplayController is always nil and the search bar does not appear.

In practice I have replicated MainView.xib from the TableSearch example and set the file's owner class to the correct controller class for the tab. The outlets are sets as in the example MainView.xib. Am i missing any important step or doing something wrong?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

指尖微凉心微凉 2024-08-06 05:27:56

对我有用的另一个可能的修复方法是使用 initWithNibName:bundle 初始化 UITableViewController:

SearchEntryTableViewController* searchEntryTableViewController = [[SearchEntryTableViewController alloc]initWithNibName:@"SearchEntryTableViewController" bundle:nil];

将 UITableViewController 嵌套在 UINavigationController 中,然后将其放入 UITabBarController 中并不能解决我的问题...

Another possible fix that works for me is to init the UITableViewController with initWithNibName:bundle:

SearchEntryTableViewController* searchEntryTableViewController = [[SearchEntryTableViewController alloc]initWithNibName:@"SearchEntryTableViewController" bundle:nil];

To nest the UITableViewController in a UINavigationController before put it in a UITabBarController doesn't fix the issue for me...

游魂 2024-08-06 05:27:56

如果您的 nib 文件包含 UITableViewController,Tomtrapeze 就有正确的答案。 但是,如果您在代码中加载 UITableViewController(例如将其推送到 UINavigationController 的堆栈上),则解决方案会略有不同。

初始化 UITableViewController 或子类时,您需要使用 -initWithNibName:bundle: 形式的初始化程序并指定 nib 文件的名称。 或者,您可以使用标准 -initWithStyle: 初始化程序并在加载视图之前手动设置 nibName 属性。

如果加载视图时未设置 nibName 属性,UITableViewController 将不会使用正常的 UIViewController nib 查找逻辑。 它只会加载一个标准的 UITableView。

Tomtrapeze has the right answer if your nib file contains the UITableViewController. But, if you're loading the UITableViewController in code -- such as pushing it on the stack of a UINavigationController -- the solution is a little different.

When initializing the UITableViewController or subclass, you need to use the -initWithNibName:bundle: form of initializer and specify the name of your nib file. Alternately, you could use the standard -initWithStyle: initializer and manually set the nibName property before the view is loaded.

If the nibName property is not set when the view gets loaded, UITableViewController will not use the normal UIViewController nib lookup logic. It will just load a standard UITableView instead.

花开柳相依 2024-08-06 05:27:56

我最近了解到,当 NIB 文件与类同名时(即 MyViewController.xib< /代码>)。 事实证明,以这种方式初始化会导致“UISearchBarandUISearchBarDisplayController”不显示。 当我通过实际键入类名称来初始化视图控制器时,我的搜索栏正确显示。 我最初认为这与我呈现视图控制器的方式有关,但很高兴事实并非如此。

PGWSearchViewController *searchVC = [[PGWSearchViewController alloc] initWithNibName:@"PGWSearchViewController" bundle:nil];

searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
searchVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentViewController:searchVC animated:YES completion:^{ }];

这是使用 iOS SDK 5.1 和 XCode 4.3.1。

I recently learned that I could load NIB files with [[MyViewController alloc] initWithNibName:nil bundle:nil]; when the NIB file has the same name as the class (i.e. MyViewController.xib). It turns out that initializing this way causes the 'UISearchBarandUISearchBarDisplayController` to not display. When I initialized the view controller by actually typing out the name of the class, my search bar showed up correctly. I initially thought it had something to do with how I was presenting the view controller but was glad that it wasn't.

PGWSearchViewController *searchVC = [[PGWSearchViewController alloc] initWithNibName:@"PGWSearchViewController" bundle:nil];

searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
searchVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentViewController:searchVC animated:YES completion:^{ }];

This is using iOS SDK 5.1 and XCode 4.3.1.

那请放手 2024-08-06 05:27:55

我遇到了同样的问题,碰巧偶然发现了这个解决方案...

如果您使用 Interface Builder 将表视图控制器(例如 UISearchDisplayController)嵌套在选项卡栏或导航控制器中,则需要设置“属性检查器”窗口中的“笔尖名称”。

Nib 名称将是保存表视图并具有作为文件所有者的控制器(例如 UISearchDisplayController)的名称。

I had the same issue and happened to stumble upon this solution ...

If you have your table view controller (eg. UISearchDisplayController) nested in a Tab Bar or Navigation controller using Interface Builder, you need to set the "Nib Name" in the "Attributes Inspector" window.

The Nib name will be the one that holds the table view and has the controller (eg. UISearchDisplayController) as the File's Owner.

甜心 2024-08-06 05:27:55

我也有这个问题:(搜索栏是否隐藏在表格视图后面?

@unforgiven,
你尝试过这个吗...?

searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)]; 
[self.tableView setTableHeaderView: searchBar];

这手动创建了一个搜索栏并且它可以工作。 但我在 IB 中犯了一些愚蠢的错误,即使我的连接是完美的,搜索栏也没有显示。 :-(

如果您得到答案,请更新这篇文章......

I too have this issue :( Is the search bar getting hidden behind the tableview?

@unforgiven,
did you try this...?

searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)]; 
[self.tableView setTableHeaderView: searchBar];

This manually creates a searchbar and it works. But I'm making some stupid mistake in IB that the SearchBar doesn't show up even though my connections are perfect. :-(

Do update this post if you get the answer...

Hello爱情风 2024-08-06 05:27:55

好的,我已经找到解决方法了。 就我而言,问题是由于我使用嵌入 UITabBarController 中的控制器作为其托管选项卡之一(即作为子选项卡)。

从 UITabBarController 中删除控制器,然后将 UINavigationController 添加到 UITabBarController 中,最后将我的控制器作为 UINavigationController 的子级完全解决了问题。

我不明白为什么会这样(文档中没有相关信息,就像经常发生的那样); 然而,它现在就像一个魅力。
亲切的问候。

Ok, I have found how to solve it. In my case, the problem was due to the fact that I was using a controller embedded within the UITabBarController as one of its managed tabs (i.e. as a child).

Removing the controller from the UITabBarController, then adding an UINavigationController to the UITabBarController instead, and finally putting my controller as a child of the UINavigationController solved completely the issue.

I do not understand why this is so (there is no related information in the documentation, as often happens); however, it now works like a charm.
With kind regards.

匿名。 2024-08-06 05:27:55

我有一个类似的问题

要解决,我必须对不可原谅的答案执行一个额外的步骤
在我的主笔尖中

1) 创建一个 UITabController
2)然后我将 UINavigational Controller 拖出到选项卡控制器中
3)然后拖出一个UITableViewController作为子项放入NavigationalController中
4)然后在检查器中将(3)类更改为我的MyTableWithSearchBarViewController - 检查笔尖名称是否正确,并根据需要在检查器中更改它
5)然后我必须删除IB在步骤(3)中自动创建的tableView。 只有这样搜索栏才会正确显示...

如果在步骤 3 中我将另一个控制器拖到舞台上或将 tableView 留在那里,它只会显示表格而不是搜索栏,这

很奇怪

I had a similar issue

To solve I had to do one additional step to unforgivens answer
In my main nib

1) create a UITabController
2) Then I dragged out a UINavigational Controller into the tab controller
3) Then dragged out a UITableViewController into the NavigationalController as a child
4) Then changed (3) class to be my MyTableWithSearchBarViewController in the inspector - check if the nib name is correct and change this if necessary in the inspector as well
5) I then had to delete the tableView which is automatically created by IB in step (3). Only then would the search bar show correctly...

If in step 3 I dragged out a different controller onto the stage or left the tableView there it would only ever display the table and not the search bar

weird

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文