NIB 文件在运行时不显示

发布于 2024-10-06 20:21:25 字数 708 浏览 0 评论 0原文

我正在为这件事抓狂。我有一个带有两层 TableViews 的 NavigationController 。每个 TableView 都位于其自己的 NIB 文件中。第一级仅显示一个列表。选择一个单元格后,它会将用户带到带有更详细列表的第二级 TableView。我想在第二级 TableView 上显示搜索栏(实际上我也在使用 SearchDisplayController)。我已将其添加到 TableView 中,因为我希望 SearchBar 随表格一起滚动。

下面,我展示了两个屏幕截图。首先是InterfaceBuidler中的第二级tableview。第二个是运行时的二级表视图。由于某种原因,SearchBar 在运行时不显示。

我尝试从头开始创建一个全新的项目,但同样的事情发生了。我不明白为什么 SearchBar 不显示在 NavigationController 上推送的 NIB 上。

在你问之前,如果我将 SearchBar 放在第一级 TableView 上,它就会显示得很好。是的,我将它添加到 TableView 本身,因此它是应该显示的视图的一部分。

帮助!我做错了什么?

XIB File

这是推送 XIB 后实际显示的内容...

搜索栏不显示?

I am pulling my hair out on this one. I have a NavigationController with two levels of TableViews. Each TableView is in its own NIB file. The first level simply displays a list. Upon selecting a cell, it takes the user to a second level TableView with a more detailed list. It is on this second level TableView that I want to display a search bar (actually I am using a SearchDisplayController as well). I have added it to the TableView because I want the SearchBar to scroll with the table.

Below, I am displaying two screenshots. The first is the second level tableview in InterfaceBuidler. The second is the second level tableview at runtime. For some reason, the SearchBar doesn't display at runtime.

I have tried creating a completely new project from scratch and the same things happens. I don't understand why the SearchBar doesn't display on a NIB pushed on the NavigationController.

Before you ask, if I put the SearchBar on the first level TableView, it shows up just fine. Yes, I am adding it to the TableView itself, so it is a part of the view that should be displayed.

Help! What am I doing wrong?

XIB File

This is what actually displays after the XIB is pushed...

SearchBar Doesn't Display?

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

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

发布评论

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

评论(3

亽野灬性zι浪 2024-10-13 20:21:25

好吧,我必须回答我自己的问题。我考虑过删除它,但这也许可以帮助其他人。我真的对这个感到抓狂。这并不是因为我做错了什么,而是因为我对 iPhone 开发的工作原理产生了根本性的误解。

简而言之,问题出在这行代码上,它实例化了TableViewController:

self.downloadDetailViewController = [[DownloadDetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

当你使用XCode创建一个新类时,可以使用以下命令:

“Add -> New File -> Cocoa Touch Class -> Cocoa Touch Class”。 UIViewController 子类 -> UITableViewController
子类和使用 XIB 作为用户界面”

问题是,NIB 与 UITableViewController 绝对没有任何关系,除非你告诉你的代码使用它。对我来说,这似乎是 XCode 中的一个错误,或者至少是违反直觉的东西当开发环境一起创建所有三个文件时,它们只能一起工作才有意义,但它们不会一起工作,

解决方案是修改代码行如下:

self.downloadDetailViewController = [[DownloadDetailTableViewController alloc] initWithNibName:@"SecondaryView" bundle:[NSBundle mainBundle]];

希望这可以帮助其他人。 。

Okay, I'm going to have to answer my own question. I thought about deleting it, but perhaps this could help someone else. I really pulled my hair out on this one. It wasn't because of anything I was doing wrong so much as a fundamental misunderstanding of how iPhone development works.

In a nutshell, the problem was with this line of code, which instantiated the TableViewController:

self.downloadDetailViewController = [[DownloadDetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

When you use XCode to create a new class, you can use the following:

"Add -> New File -> Cocoa Touch Class -> UIViewController subclass -> UITableViewController
subclass AND With XIB for user interface"

The problem is that the NIB has absolutely nothing to do with the UITableViewController until you tell your code to use it. To me, this seems like a bug in XCode or at the very least something that is counterintuitive. When the development environment creates all three files together, it would only make sense that they would work together, but they don't.

Instead, the solution is to modify the line of code as follows:

self.downloadDetailViewController = [[DownloadDetailTableViewController alloc] initWithNibName:@"SecondaryView" bundle:[NSBundle mainBundle]];

Hopefully this can help someone else...

策马西风 2024-10-13 20:21:25

您还可以在选项卡栏控制器下的下载视图控制器上设置 Nib Name 属性,事实上,再加上使用类名设置类,将自动为您创建视图,而无需手动创建它。

You could also set Nib Name property on your Download View Controller under the Tab Bar Controller, in fact that and coupled with setting the class with your class name will automatically create the view for you and you don't have to manually create it.

我不是你的备胎 2024-10-13 20:21:25

我认为问题是您将搜索栏添加到 tableView 中,因此它没有显示。

尝试添加该搜索栏而不添加到表视图,这意味着将表视图向下移动一些并将搜索栏添加到视图(而不是表视图)。

I think the problem is that you are adding the searchbar to the tableView, so it is not displaying.

Try to add that searchBar with out adding to the table view, that means move the table view some what down and add the search bar to the view(not the tableview).

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