根控制器放在哪里?
我在 xcode 中为 iPhone 做事变得越来越好,但在这里我遇到了死胡同。
我正在尝试构建一个具有两个视图的应用程序:主视图和设置视图。我希望能够在两者之间切换。由于我需要主视图中的每个像素,因此我构建了一个 switchView 类,当我按下按钮时(比 tabView 小得多),它可以在两个视图之间切换,效果很好。
现在,我的开发更加深入,希望设置视图成为一个表格视图,我可以从其中导航到下一个详细级别。我以前做过这个,但没有切换视图。
我的问题是我让表视图(在设置中)正常工作,但是一旦我尝试推送视图控制器,什么也没有发生。在调试时,我可以看到它通过代码工作(例如 didSelectRowAtIndexPath 正在工作),但没有弹出新视图。也没有任何错误消息。
我在 MainWindow.xib 中添加了 switchView,然后执行 [窗口addSubview:switchViewController.view];在我的 AppDelegate 中加载主视图。
我应该将表视图导航的根控制器放在哪里?因为我想这就是我遇到的问题?
下面的代码不会产生任何结果...
ViewsAppDelegate *delegate =[[UIApplication sharedApplication] delegate];
[delegate.settingsNavController pushViewController:settingsDetailViewController animated:YES];
很高兴有任何可以引导我走上正轨的建议。花了太多时间来解决这个问题。
I'm getting better and better with doing things for the iPhone in xcode, but here I have ran into a dead end.
I'm trying to build an app with two views: the main one and one for settings. I want to be able to switch between the two of them. Since I need every pixel in the main view I have built a switchView class that simply switch between the two views when I press a button (so much smaller than a tabView), which is working fine.
Now I'm a bit deeper in development and want the settings view to be a table view from where I can navigate to the next level of detail. I have done this before, but without the switch view.
My problem is that I get the table view (in settings) to work, but once I try to push my view controller nothing happens. While debugging I can see that it works through the code (eg didSelectRowAtIndexPath is working) but no new view pops up. Neither any error message.
I have the switchView added in my MainWindow.xib and then do a
[window addSubview:switchViewController.view]; in my AppDelegate to load the main view.
Where should I put the root controller for the navigation for the table view? Because I guess that's the problem I have?
Below the code that results in nothing...
ViewsAppDelegate *delegate =[[UIApplication sharedApplication] delegate];
[delegate.settingsNavController pushViewController:settingsDetailViewController animated:YES];
Happy for any suggestions that could lead me to the right track. Spent way too much time to solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会误解你想要的东西,但让我尝试一下......
当你创建项目时,你应该已经为你启动并创建了 MainViewController 和 AppDelegate 。从您提供的代码片段来看,它看起来就像您从 MainViewController 中实例化一个新的(可能是第二个)应用程序委托。
我建议您将 NavigationController 向上移动一级到 SDK 提供的 AppDelegate,而不是这样做。然后在您的 MainViewController 中,添加现有的 AppDelegate 作为 IBOutlet 并将它们全部绑定在 IB 中。完成此操作后,使用导航控制器应该会更加顺利。
例如,我的 MainWindow.xib 有几个对象,我突出显示了我认为您可能关心的两个对象...
http://www.freeimagehosting.net/uploads/f50268da03.png
*抱歉链接 - 我还无法发布图像。
然后,从我的 AppDelegate 中,我像这样自定义我的 applicationDidFinishLaunchingWithOptions...
这使 navController 保持在最高级别(我认为它所属的位置),并允许您在整个应用程序中推送和弹出视图,同时保留应用程序上内容的历史记录堆。
希望有帮助 - 我可能完全误解了你的目的。
祝你好运!
鲍勃
I might be misunderstanding what you're after, but let me try...
When you created your project you should have gotten your MainViewController and an AppDelegate both spun up and created for you. From the snippet you've provided it looks to me like your instantiating a new (and possibly second) app delegate from within your MainViewController.
Rather than doing this, I would suggest that you move your NavigationController up one level to the AppDelegate supplied by the SDK. Then in your MainViewController, add the existing AppDelegate as an IBOutlet and tie them all together in IB. Once you've done that, using the navigation controller should go much more smoothly.
For example, my MainWindow.xib has several objects, and I've highlighted the two that I think you're probably concerned with...
http://www.freeimagehosting.net/uploads/f50268da03.png
*Sorry for the link - I can't post images yet.
Then, from my AppDelegate I customize my applicationDidFinishLaunchingWithOptions like so...
That keeps the navController up at the highest level (where I think it belongs) and allows you to push and pop views throughout the entire app while keeping that history of what's on the stack.
Hope that helps - I might have completely misunderstood what you were after.
Good Luck!
Bob