切换到另一个选项卡时在选项卡中保留新视图

发布于 2024-10-06 13:54:42 字数 1089 浏览 0 评论 0原文

情况是这样的:

我有一个带有 2 个选项卡的选项卡栏。选项卡01 和选项卡02。 在Tab01中,我有一个按钮可以推动repVC:

    repVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:repVC animated:YES];
    [(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
    [repVC release];

在repVC内部,我有另一个按钮可以推动MFMailComposerViewController

    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    [self presentModalViewController:mail animated:YES];
    [mail release];

问题是:当显示mailView时(在Tab01中),我单击Tab02,然后返回Tab01, mailView 被隐藏,即使我再次单击电子邮件按钮,该视图也不会显示。

所以我所拥有的是:

Tab01.view -> repVC.view -> mail.view 

对于 repVC,我在推送视图时使用这一行,这样即使我切换选项卡,该视图仍然会被激活:

   [(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];

但我不能对 ma​​il 因为 tabController 是在另一个我无法导入的类中声明的。所以我无法访问 tabController 并设置 Tab01 的视图。

希望编辑有助于理解。

This is the situation:

I have a tab bar with 2 tabs. Tab01 and Tab02.
In Tab01 I have a button which pushes repVC:

    repVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:repVC animated:YES];
    [(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
    [repVC release];

Inside repVC I have another button which pushes an MFMailComposerViewController:

    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    [self presentModalViewController:mail animated:YES];
    [mail release];

The problem is: when mailView is shown(in Tab01) and I click Tab02, then back to Tab01, the mailView is hidden and even if I click the email button again, the view won't be presented.

So what I have is:

Tab01.view -> repVC.view -> mail.view 

For repVC, I use this line when I push the view so that even if I go switch tabs, that view will still be activated:

   [(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];

But I can't do the same for mail because tabController is declared in another class which I cannot import. So I can't access the tabController and set the view for Tab01.

Hope the edit helped the understanding.

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

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

发布评论

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

评论(3

噩梦成真你也成魔 2024-10-13 13:54:42

嗯,

我仍然建议使用导航控制器。会让事情变得更容易,符合苹果的指导方针和建议,并且实施得相当快。 (只需创建一个Navigationcontroller,将Tab1的View作为主视图并将其交给TabbarController。然后对于mailView使用 [self.navigationController PushViewController:mailanimated:YES]; 然后navcontroller为您“保存”当前视图 什么

但是如果由于某种原因你必须使用 modalViewcontroller,你可以在显示 ModalView 时停用选项卡栏,或者尝试在 ViewWillAppear 中实现一个开关或一个简单的 if...else 情况,你可以在其中检查 屏幕加载。
然后清理窗口并加载右侧屏幕。

希望你能明白我的意思,有时我的写作方式似乎会让人们感到困惑。 ^^

Hmm,

I still would suggest to use a Navigationcontroller. Would make things way easier, is conform to apple guidelines and suggestions and is pretty fast implemented. (Just create a Navigationcontroller, put the View of Tab1 as main view and hand it over to the TabbarController. Then for the mailView use [self.navigationController pushViewController:mail animated:YES]; Then the navcontroller "saves" the present view for you when u switch tabs)

But if for some Reason you have to use a modalViewcontroller you could either just deactivate the tabbar while the ModalView is shown or try to implement a switch or a simple if...else case in your ViewWillAppear where u check what screen to load.
Then Clean out the Window and load the right screen.

Hope you get the idea of what I mean, sometimes my way of writing seems to confuse people. ^^

北凤男飞 2024-10-13 13:54:42

如果能提供更多信息就更好了。

你是如何设置 TabbarController 的?

你如何推动新观点?在 UINavigationController 中?如果没有,那么用 navController 来做,他应该保存视图的实际状态,你的问题应该得到解决。

如果您已经使用 navController,请发布选项卡 1 的 Viewcontroller 的 ViewDidLoad 和 ViewWillAppear

A little more information would be great.

How did u set up your TabbarController?

How do u push the new view? Within a UINavigationController? If not, then do it with a navController, he should save the actual state of view and your problem should be solved.

If u already use a navController please post your ViewDidLoad and ViewWillAppear of the Viewcontroller of Tab 1

旧伤还要旧人安 2024-10-13 13:54:42

正如 @Amandir 指出的,您可能可以通过使用 UINavigationController 来解决您的问题。我有一种感觉,您试图稍微滥用模态视图控制器概念,这就是为什么它不能按您的预期工作的原因。当您使用 presentModalViewController:animated: 时,您的意图应该是显示模态视图,即用户必须交互并关闭模态视图,然后才能继续。

上面的段落意味着当您呈现模态视图控制器时,它不应该可以使用标签栏。由于您使用的是“推送”一词,我猜测您希望更改 Tab01 的视图,同时仍然能够使用选项卡栏的功能。问题是除了 UINavigationController 之外,没有任何内置的方法来推送视图控制器。 persentModalViewController:animated: 只应在您需要模态视图的情况下使用,这在 iPhone 上意味着全屏视图。

最简单的方法可能是使用 UINavigationController 并隐藏导航栏。然后你就会得到我认为你想要的功能。另一个选项是手动添加和删除子视图。

[self.view addSubview:repVC.view];

[repVC.view removeFromSuperview];
[self.view addSubview:mail.view];

如果您想要一些奇特的过渡,您可以使用块动画

As @Amandir points out you could probably solve your problems by using a UINavigationController. I get a feeling that you are trying to abuse the modal view controller concept a bit and that's why it doesn't work as you expect. When you use presentModalViewController:animated: the intention should be that you are displaying a view that is modal, i.e. the user must interact and dismiss the modal view before she can continue.

What the paragraph above means that when you present a modal view controller it shouldn't be possible to use the tab bar. Since you are using the word push I'm guessing that you would like change the view of Tab01 while still being able to use the functionality of the tab bar. The problem is that there isn't any built-in method of pushing view controllers besides UINavigationController. persentModalViewController:animated: should only be used in case where you want a modal view, which on the iPhone means a full screen view.

The easiest way would probably be to use an UINavigationController and hide the navigation bar. Then you would get the functionality I think you are after. The other option is to manually add and remove sub views.

[self.view addSubview:repVC.view];

and

[repVC.view removeFromSuperview];
[self.view addSubview:mail.view];

You can use block animations if you want some fancy transitions.

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