2

我有一个带有打开另一个应用程序的操作(toggleApplication)的按钮。当我从打开的应用程序返回应用程序时,我想转到另一个视图。但我从我的代码中得到以下错误:

接收器(RootViewController:0x1f192450)没有标识符为“showReceipt”的segue

AppDelegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

        RootViewController *controller = [RootViewController alloc];

        return [controller handleURL:url];

    }

根视图控制器.m

- (IBAction)toggleApplication:(id)sender{

     // Open application
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrlString]];

}

- (BOOL)handleURL:(NSURL *)url{

     [self performSegueWithIdentifier:@"showReceipt" sender:self];

     return YES;

}
4

1 回答 1

3

通过使用 NSNotificationCenter 弄清楚了。

AppDelegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

        [[NSNotificationCenter defaultCenter] postNotificationName:@"segueListener" object:nil];

        return YES;

    }

根视图控制器.m

- (void)viewDidLoad{

     [super viewDidLoad];

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptSegue) name:@"segueListener" object:nil];

}    

- (IBAction)toggleApplication:(id)sender{

     // Open application
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:theUrlString]];

    }

   - (void)receiptSegue{
        [self performSegueWithIdentifier:@"showReceipt" sender:self];
   }

正是我想要的。不知道这是否是正确的方法。

于 2013-03-27T14:28:55.273 回答