Ios presentViewController不工作appdelegate
行Ios presentViewController不工作appdelegate,ios,iphone,Ios,Iphone,行presentViewControllercrash应用程序 @interface VVPassbook : NSObject @property (nonatomic, retain) id delegate; -(void)gotPassbookFromUrl:(NSURL *)passbookUrl; @end #import "VVPassbook.h" @implementation VVPassbook -(void)gotPassbookFromUrl:(NS
presentViewController
crash应用程序
@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
im在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>.'
原因:“应用程序试图在目标上呈现一个nil模式视图控制器。”
您应该从UIViewController(即自我)提供一个viewController
(如果self是viewcontroller)
请注意,当self(此viewcontroller)从主窗口分离时,您将收到“尝试显示其视图不在窗口层次结构中的对象”警告
解决方案:始终使用addChildViewController:to ChildViewController。为什么要使用
self.delegate
来推送视图控制器
,
简写
[self presentViewController:vc animated:YES completion:nil];
代替
[self.delegate presentViewController:vc animated:YES completion:nil];
您只需在视图控制器上调用它,而不是在其委托上调用它。。[自我呈现视图控制器:vc动画:是完成:无];你的问题不清楚这里的“自我授权”是什么??请澄清你的问题。