我在视图控制器上有一个按钮,我想点击按钮,然后进入一个网站。 该网站在parse.com上举行。
代码如下
- (IBAction)WebAddressBtn:(id)sender {
NSString *url = [self.exam objectForKey:@"Website"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSLog(@"website: %@",url);
}
NSLog
显示值为url
但数据保存在
self.exam objectForKey:@"Website"
NSLog确认其存在
这可行并将转到谷歌
- (IBAction)WebAddressBtn:(id)sender {
NSString *url = @"http://www.google.com";
//[self.exam objectForKey:@"Website"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
NSLog(@"website: %@",url);
}
如果我尝试
NSURL *url = [self.exam objectForKey:@"Website"];
url仍显示为Null 但我知道数据在self.exam objectForKey:@"网站
数据的NSLog输出
name = "DMK Media & Photography Ltd";
phone1 = 01993835148;
phone2 = 07795966848;
postcode = "OX28 4BT";
products = "<PFRelation: 0x10dc75320>(<00000000 00000000>.(null) -> products)";
website = "http://www.dmkmedia.co.uk";
答案 0 :(得分:2)
[UIApplication sharedApplication]如果没有格式正确的url,openURL将无法正常工作。请检查您的网址是否为&#34; http://&#34;