显示控制器的iOS问题

时间:2014-10-27 15:28:07

标签: ios objective-c

我尝试使用以下代码在我的视图控制器上显示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];)时,我应该看到带有我的存折的视图控制器,我可以将存折添加到库中,但它不起作用。我哪里出错了?

编辑:

另外如果我调试我的路径对象是nil。

1 个答案:

答案 0 :(得分:1)

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