显示 Controller 的 iOS 问题

标签 ios objective-c

我尝试使用以下代码在我的 View Controller 上显示 PKAddPassesViewController:

[self.helper alert:@"Attenzione" message:@"Grazie per la registrazzione. Ti aspettiamo in uno dei nostri centri Surfree" delegate:self];

//load StoreCard.pkpass from resource bundle
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"surfree" ofType:@"pkpass"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSError *error;

//init a pass object with the data
PKPass *pass = [[PKPass alloc] initWithData:data error:&error];

//init a pass library
PKPassLibrary* passLib = [[PKPassLibrary alloc] init];

//check if pass library contains this pass already
if([passLib containsPass:pass]) {

    //pass already exists in library, show an error message
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pass Exists" message:@"The pass you are trying to add to Passbook is already present." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];

} else {

    //present view controller to add the pass to the library
    PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
    [vc setDelegate:(id)self];
    [self.navigationController pushViewController:vc animated:YES];
    //[self presentViewController:vc animated:YES completion:nil];
}

从逻辑上讲,当调用此行时 ([self.navigationController pushViewController:vc animated:YES];) 我应该看到带有我的存折的 View Controller ,我可以在其中将存折添加到库中,但是它不起作用。我哪里出错了?

编辑:

此外,如果我进行调试,我的路径对象为 nil。

最佳答案

    PKAddPassesViewController *addPassViewController = [[PKAddPassesViewController alloc] initWithPass:newPass];
    addPassViewController.delegate = self;
    [self presentViewController:addPassViewController animated:YES completion:nil];

关于显示 Controller 的 iOS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26591028/

相关文章:

ios - UISearchbar 上的取消按钮

ios - 代码 : module name "" is not a valid identifier while running XC unit test

ios - iMessage 应用程序 - 以编程方式从 .apng 创建动画贴纸

ios - 您可以将 UIView 剪辑 subview 限制在 View 的某些侧面吗?

ios - UIButton 文本仅在触摸时出现

ios - 不要将 HMSegmentedControl 与 Storyboard一起使用

objective-c - 为什么 NSURLConnection 无法到达后端?

ios - 未在不同线程上调用委托(delegate)

ios - 调用 viewDidLoad 后,viewcontroller 的属性消失

objective-c - UIImagePickerController 不会录制视频