如何在选项卡栏应用程序中更改 XIB?

发布于 2024-08-05 23:18:37 字数 152 浏览 3 评论 0原文

我的 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 技术交流群。

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

发布评论

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

评论(3

柒七 2024-08-12 23:18:37

您的选项卡视图控制器可能具有其操作方法,例如 -(IBAction)onChangeView 并且该方法调用 [[UIApplication sharedApplicaton] delegate] 上的方法,例如 <代码>-(void)切换屏幕。

-(IBAction)onChangeView:(id)sender
{
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate toggleScreen];
}

然后在您的应用程序委托方法中执行如下操作:

-(void)toggleScreen
{
    [[[window subviews] objectAtIndex:0] removeFromSuperview];
    [window addSubview:otherView];
}

但是,如果您需要转换,情况可能会有所不同。

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.

-(IBAction)onChangeView:(id)sender
{
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate toggleScreen];
}

Then in your app delegate method do something like this:

-(void)toggleScreen
{
    [[[window subviews] objectAtIndex:0] removeFromSuperview];
    [window addSubview:otherView];
}

It may be different if you need transitions, however.

豆芽 2024-08-12 23:18:37

您实际上不必一路走到应用程序委托。您可以轻松删除现有视图和控制器并添加新视图。这确实取决于你在做什么。例如,您可以暂时搁置现有的视图结构并采用完全不同的东西,如果您愿意的话可以返回到原始方案(尽管我不确定用户体验)。

在我的应用程序中,我通常有一个根视图控制器,或者我使用主窗口添加视图和从中删除视图。某些视图会将其他视图添加到自身或将另一个视图转换到根视图或主窗口上。有些视图会自行关闭以显示下面的视图。选项是无限的,取决于您的需求和架构。

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.

桃扇骨 2024-08-12 23:18:37

谢谢你们!尼克,这正是我需要的代码。如果有人觉得这很方便,这里是我用来添加动画来切换视图的代码。只需将其放入应用程序委托的方法中即可:

AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];
[[[window subviews] objectAtIndex:0] removeFromSuperview];
[window addSubview:[anotherViewController view]];
[UIView commitAnimations];

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:

AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];
[[[window subviews] objectAtIndex:0] removeFromSuperview];
[window addSubview:[anotherViewController view]];
[UIView commitAnimations];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文