2013-10-19 39 views
0

當我點擊應用程序時,我的應用程序中有一個按鈕應該帶您到存儲在plist中的商業網站。我可以得到按鈕來處理這段代碼:Xcode中的Plist的超鏈接

-(IBAction)search:(id)sender{ 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]]; 
} 

現在我該如何操縱這個代碼來調用已經建立的plist網站。

+0

這項工作適合您嗎? – AdamG

回答

2

從p列表中獲取鏈接字符串。

NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]]; 
NSString * urlString = dictionary[@"TheKeyPath"]; // theKeyPath referring to the key that you assigned to the url string in the p-list 

然後很簡單...

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; 
0

我這樣寫這一點,但按鈕永遠不會出現做任何事情,我寫了的NSLog和它按一下按鈕,但不發送到野生動物園。

-(IBAction)search:(id)sender{ 
    NSString *searchsite = [resultDic objectForKey:@"Search"]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:searchsite]]; 
} 

什麼是混淆是我有一個調用函數這樣寫,它工作得很好。

-(IBAction)callPhone:(id)sender { 

    NSString* yourActualNumber = [NSString stringWithFormat:@"tel:%@",resultDic[@"Phone"]]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:yourActualNumber]]; 
}