我使用Safari瀏覽網頁。點擊此頁面上的按鈕後,我的iPad會啓動我的應用程序。因此,我在AppDelegate.m
中實施了方法- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
。如何將數據從AppDelegate傳遞給ViewController?
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if (!url) { return NO; }
NSString *URLString = [url absoluteString];
self.paramArray = [URLString componentsSeparatedByString:@"@"];
NSLog(@"%d",[self.paramArray count]);
for (int i = 1; i < [self.paramArray count]; i++) {
NSLog([self.paramArray objectAtIndex:i]);
}
return YES;
}
我在網頁上使用的網址有點像myapp://@[email protected][email protected]_part
。 self.paramArray
存儲url的子字符串(myapp://
first_part
second_part
third_part
)。
現在我想在我的ViewController
的textfields中顯示這些字符串。我怎樣才能通過這個NSArray到ViewController
?
可以給我更多詳細資料嗎?像我應該在哪裏添加這些行? – Manted
這樣可以嗎?或需要更多信息? :) –
我做了你告訴我的。但我的'viewDidLoad'方法中的'[appDel.paramArray count]'返回'0'。何時會調用' - (BOOL)應用程序:(UIApplication *)application handleOpenURL:(NSURL *)url'? – Manted