presentViewController没有工作appdelegate

时间:2015-04-09 08:46:13

标签: ios iphone

presentViewController崩溃应用

@interface VVPassbook : NSObject

@property (nonatomic, retain) id delegate;

-(void)gotPassbookFromUrl:(NSURL *)passbookUrl;

@end

#import "VVPassbook.h"

@implementation VVPassbook

    -(void)gotPassbookFromUrl:(NSURL *)passbookUrl
{
        //present view controller to add the pass to the library
                PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
                [vc setDelegate:(id)self.delegate];
                [self.delegate presentViewController:vc animated:YES completion:nil];
}
    @end

我在方法

中的AppDelegate.m中调用此方法
    - (void)application:(UIApplication*)application didReceiveRemoteNotification:
    (NSDictionary*)userInfo
{
VVPassbook *pass = [[VVPassbook alloc] init];
pass.delegate = self.window.rootViewController;
[pass gotPassbookFromUrl:MYURL ];
}

所有时间错误

reason: 'Application tried to present a nil modal view controller on target <VVRightManuViewController: 0x15dd28460>.'

2 个答案:

答案 0 :(得分:0)

你应该从UIViewController呈现一个viewController,即self (如果self是一个viewcontroller)。

请注意,您将获得一个&#34;尝试显示其视图不在窗口层次结构中&#34; -warning当self(此viewcontroller)与主窗口分离时。

解决方案:始终使用addChildViewController:to child viewcontrollers。

答案 1 :(得分:0)

为什么您使用self.delegate push view Controller, 简单写

[self presentViewController:vc animated:YES completion:nil];

代替

 [self.delegate presentViewController:vc animated:YES completion:nil];