如何在选项卡栏应用程序中更改 XIB?
我的 iPhone 应用程序是基于选项卡栏的,但我想触发一个操作,完全切换选项卡栏控制器视图,并用来自不同 XIB 文件的视图替换窗口中的所有内容。我猜想这必须在应用程序委托中完成(因为这是“首席”类),但我不知道从那里开始的正确方法。有谁知道如何做我想做的事?
提前致谢!
My iPhone app is tab bar-based, but I would like to fire an action which switches out the tab bar controller view completely and replaces everything in the window with a view from a different XIB file. I would guess this has to be done in the application delegate (since this is the "chief" class), but I don't know the right way to go from there. Does anyone know how to do what I am trying to do?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的选项卡视图控制器可能具有其操作方法,例如
-(IBAction)onChangeView
并且该方法调用[[UIApplication sharedApplicaton] delegate]
上的方法,例如 <代码>-(void)切换屏幕。然后在您的应用程序委托方法中执行如下操作:
但是,如果您需要转换,情况可能会有所不同。
Your tab view controller could have it's action method, such as
-(IBAction)onChangeView
and that method calls a method on the[[UIApplication sharedApplicaton] delegate]
, such as-(void)toggleScreen
.Then in your app delegate method do something like this:
It may be different if you need transitions, however.
您实际上不必一路走到应用程序委托。您可以轻松删除现有视图和控制器并添加新视图。这确实取决于你在做什么。例如,您可以暂时搁置现有的视图结构并采用完全不同的东西,如果您愿意的话可以返回到原始方案(尽管我不确定用户体验)。
在我的应用程序中,我通常有一个根视图控制器,或者我使用主窗口添加视图和从中删除视图。某些视图会将其他视图添加到自身或将另一个视图转换到根视图或主窗口上。有些视图会自行关闭以显示下面的视图。选项是无限的,取决于您的需求和架构。
You don't really have to go all the way to the app delegate. You can easily remove your existing views and controllers and add new views. It really does depend on what you are doing. You could, for example, temporarily put aside the existing view structure and go with something totally different, and get back to the original scheme if you want (I'm not sure of the user experience though).
In my apps, I usually have a root view controller or I use my main window to add views to and remove views from. Some views will add other views to themselves or transition another view onto the rootview or main window. Some views close themselves to reveal the view below. The options are limitless, and depend on your needs and architecture.
谢谢你们!尼克,这正是我需要的代码。如果有人觉得这很方便,这里是我用来添加动画来切换视图的代码。只需将其放入应用程序委托的方法中即可:
Thanks guys! Nick, that's just the code I needed. In case anyone finds this handy, here's the code I used to add animation to switch the view. Just put this in a method in the app delegate: