UIPopOverController 与 UINavigationController 与 Xcode 4.2.1

发布于 2025-01-03 11:35:00 字数 456 浏览 2 评论 0原文

这听起来可能很简单,但不知怎的,我无法摆脱这个困境。我创建了一个空应用程序,通过在 AppDelegate.h 和 AppDelegate.m 文件中创建两个 tabBar 项目来添加它们。现在,对于我的第二个 tabBar 项目,当用户单击第二个 tabBar 项目时,我想显示一个 popOverController。我通过以下链接链接以编程方式创建了该内容。现在我的问题是我想在我的代码中使用导航控制器,我已经创建了我的 popOverController (AppDelegate.m),以便在我的 popOverController.m 中,我想使用 NavController 来推送其他视图。如果有人有一个简单的方法来实现这一目标,将不胜感激。

谢谢

this may sound simple, but somehow I am not able to get out of this. I have created an empty app, added two tabBar items by creating them in AppDelegate.h and AppDelegate.m files. Now for my second tabBar item, when the user clicks the second tabBar item I want to display a popOverController. I have programmatically created that, by following this link Link. Now my problem is I want to use Navigation Controller in my code where I have created my popOverController (AppDelegate.m) so that in my popOverController.m, I want to use the NavController to push other views. If someone has a simple way of achieving this, would be appreciated.

Thanks

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

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

发布评论

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

评论(1

御弟哥哥 2025-01-10 11:35:00

我对你的问题出在哪里有点困惑。您尝试做的事情是可能的并且应该是直接的。如果您的问题是没有推送下一个视图,因为在 popoverController 中您无权访问 self.navigationController 。如此简单的解决方案,创建一个 UINavigationController 变量并将 navigationController 传递给您的弹出窗口,或者使用通知传递要推回您的 AppDelegate 的视图。

编辑

您可以使用它来监听通知:

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(popOverViewControllerSelected:) name:@"popOverViewSelectedViewToPush" object:someObjectTellingYouWhatViewToPush];

然后使用它来发送通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"popOverViewSelectedViewToPush" object:@"ViewController1"];

选择器将是您的函数名称(我只是输入了一个描述性名称“popOverViewControllerSelected”),并且该对象需要是有关要推送的 viewController 的信息(即 1、2、3 或 @“view1”)。然后你需要:

- (void)popOverViewControllerSelected:(id)sentObject
{
     // If your passing an NSNumber could use a switch
                 switch ((int)sentObject) {
            case 0:
                //Push This view
                break;
            case 1:
                //Push that view
                break;
            case 2:
                //Push someother view
                break;
            default:
                break;
        }
}

我所说的另一种方法是在你的 popOverViewController.h 中添加

@interface .........
{
     UINavigationController *navController;
}
@property (nonatomic, retain) UINavigationController *navController;

在你的 popOverViewController.m 中添加:

@synthesize navController;

然后无论你在哪里添加 popOverViewController 只需添加:

[popOverViewController setNavController:self.navigationController];

现在在你的 PopOverViewController 中你可以调用:

[navController pushViewController:someViewController animated:YES];

但是我建议执行第一个选项。

I am little confused on where your problem is. What your trying to do is possible and should be straight forward. If your problem is that the Next view is not being pushed its because in popoverController you don't have access to self.navigationController. So easy solution, create a UINavigationController variable and pass navigationController to your popover or use notifications to pass what view to push back to your AppDelegate.

EDIT

You can use this to listen for notifications:

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(popOverViewControllerSelected:) name:@"popOverViewSelectedViewToPush" object:someObjectTellingYouWhatViewToPush];

Then use this to send the notifications:

[[NSNotificationCenter defaultCenter] postNotificationName:@"popOverViewSelectedViewToPush" object:@"ViewController1"];

The selector would be your function name (I just put a descriptive name "popOverViewControllerSelected") and the object would need to be information on what viewController to push (i.e. 1,2,3 or @"view1"). Then you would need:

- (void)popOverViewControllerSelected:(id)sentObject
{
     // If your passing an NSNumber could use a switch
                 switch ((int)sentObject) {
            case 0:
                //Push This view
                break;
            case 1:
                //Push that view
                break;
            case 2:
                //Push someother view
                break;
            default:
                break;
        }
}

The other way I was talking about is in you popOverViewController.h add in

@interface .........
{
     UINavigationController *navController;
}
@property (nonatomic, retain) UINavigationController *navController;

In you popOverViewController.m add the:

@synthesize navController;

Then where ever you are adding the popOverViewController just add:

[popOverViewController setNavController:self.navigationController];

And now in your PopOverViewController you can call:

[navController pushViewController:someViewController animated:YES];

But I recommend doing the first option.

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