简体   繁体   English

UIPopOverController与带有Xcode 4.2.1的UINavigationController

[英]UIPopOverController with UINavigationController with Xcode 4.2.1

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. 我创建了一个空应用程序,通过在AppDelegate.h和AppDelegate.m文件中创建了两个tabBar项。 Now for my second tabBar item, when the user clicks the second tabBar item I want to display a popOverController. 现在,对于我的第二个tabBar项,当用户单击第二个tabBar项时,我想显示一个popOverController。 I have programmatically created that, by following this link 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. 现在,我的问题是我想在创建popOverController(AppDelegate.m)的代码中使用导航控制器,以便在popOverController.m中使用NavController推送其他视图。 If someone has a simple way of achieving this, would be appreciated. 如果有人有一个简单的方法来实现这一目标,将不胜感激。

Thanks 谢谢

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 . 如果您的问题是未推送Next视图,因为在popoverController中您无权访问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. 如此简单的解决方案是,创建一个UINavigationController变量,然后将navigationController传递给您的弹出窗口,或使用通知来传递将其推回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 (ie 1,2,3 or @"view1"). 选择器将是您的函数名称(我只是放置了一个描述性名称“ popOverViewControllerSelected”),并且该对象需要是要推送哪个viewController的信息(即1,2,3或@“ 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 我正在谈论的另一种方式是在您的popOverViewController.h中添加

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

In you popOverViewController.m add the: 在您的popOverViewController.m中添加:

@synthesize navController;

Then where ever you are adding the popOverViewController just add: 然后在要添加popOverViewController的位置添加以下内容:

[popOverViewController setNavController:self.navigationController];

And now in your PopOverViewController you can call: 现在,在您的PopOverViewController中,您可以调用:

[navController pushViewController:someViewController animated:YES];

But I recommend doing the first option. 但我建议您选择第一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UINavigationController在UIPopOverController中不起作用 - UINavigationController not working in UIPopOverController UIPopoverController和UINavigationController削减了角落 - UIPopoverController and UINavigationController cuts corners 使用UINavigationController关闭UIPopoverController - Dismissing UIPopoverController with UINavigationController UIPopoverController与UINavigationController更改锚点? - UIPopoverController with UINavigationController change anchor point? UIPopoverController中的iOS UINavigationController和setPopoverContentSize错误 - ios UINavigationController in UIPopoverController and setPopoverContentSize error UIPopoverController在iOS 8 / Xcode 6中没有消失 - UIPopoverController not dismissing in iOS 8 / Xcode 6 UINavigationController在Xcode 9上崩溃 - UINavigationController Crashes on Xcode 9 UINavigationController的Xcode错误 - Xcode error with UINavigationController 当我将UINavigationController放在UIPopoverController中时,navigationBar没有显示 - navigationBar isn't showing when I put a UINavigationController in a UIPopoverController 在UIPopoverController中显示UIImagePickerController与现有的UINavigationController(添加后退按钮) - Showing UIImagePickerController in UIPopoverController with existing UINavigationController (adding back button)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM