解決:使用NSNotification中心,爲疑似:d
在我的AppDelegate(.M)我添加了以下程序中的OpenURL
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
... other code to handle Dropbox imported URLs
// Check to see if a file has been sent over via another app, like e-mail
if (url != nil && [url isFileURL])
{
MainViewController *firstViewController = [[MainViewController alloc]init];
[firstViewController handleOpenURL:url];
NSURL *fileFromEmail=url;
// add the url as a dictionary item, so that I can open it with NSNotificationCenter
NSDictionary *fileInfo=[NSDictionary dictionaryWithObject:fileFromEmail forKey:@"fileFromEmail"];
// add a notification named "segueListener" and pass on the dictionary object
[[NSNotificationCenter defaultCenter] postNotificationName:@"segueListener" object:nil userInfo:fileInfo];
return YES;
}
}
,然後在我的viewDidLoad MainViewController(.M) ,我添加了添加了一個NSNotification觀察:
- (void)viewDidLoad
{
[super viewDidLoad];
...
// if a notification named "segueListener" is sent out, perform the method: segueToImportFile
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(segueToImportFile:) name:@"segueListener" object:nil];
}
,然後加入handleOpenURL方法:
-(void) handleOpenURL:(NSURL *)url
{
// capture the url and store it into _importedFileURL (NSURL)
_importedFileURL=url;
}
和segueToImportFile方法:
-(void)segueToImportFile:(NSNotification *)notification
{
NSDictionary *file=[notification userInfo]; // get the dictionary object userInfo
_importedFileURL=[file objectForKey:@"fileFromEmail"];
[self performSegueWithIdentifier:@"Select Course for Import" sender:self];
}
終於SEGUE將在_importedFileURL發送到新TableViewController,列出了課程:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *navigationController=segue.destinationViewController;
SelectCourseTableViewController *selectCourseTableViewController=[[navigationController viewControllers]objectAtIndex:0];
[email protected]"Email Import"; // from the storyboard
selectCourseTableViewController.importedFile = _importedFileURL;
}