2013-04-15 56 views
0

打开URL我有一个变量agencyWebsite,当用这种方法点击应该打开网站标签:与变量语法

- (void)website1LblTapped { 
    NSURL *url = [NSURL URLWithString:self.agencyWebsite]; 
    [[UIApplication sharedApplication] openURL:url]; 
} 

我得到的编译器警告说:

Incompatible pointer types sending UILabel* to parameter of type NSString* 

当链接被点击时,应用程序崩溃。有什么建议么?

编辑:这是我在做什么,以使标签可点击

UITapGestureRecognizer* website1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(website1LblTapped)]; 
    // if labelView is not set userInteractionEnabled, you must do so 
    [self.agencyWebsite setUserInteractionEnabled:YES]; 
    [self.agencyWebsite addGestureRecognizer:website1LblGesture]; 

是我用得到它的工作

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", self.agencyWebsite.text]]; 

回答

1

如果agencyWebsiteUILabel*类型的,你需要访问它的而不是将对象本身传递给URLWithString:

- (void)website1LblTapped { 

    NSURL *url = [NSURL URLWithString:self.agencyWebsite.text]; 
    [[UIApplication sharedApplication] openURL:url]; 
} 

调用self.agencyWebsite将返回你UILabel*对象,而self.agencyWebsite.text将返回一个包含从标签中的文本NSString*对象。

+0

好吧,这有很大的意义,我已经做了更改,没有更多的错误或崩溃,但现在没有任何反应,当我点击标签:( – BluGeni

+1

它有一个URI方案吗?例如'http://' –

+0

好吧,它现在看起来像一个不同的问题:)对不起,但你必须提供更多的细节。我相信你最好开一个新的问题,因为你似乎已经解决了你最初的问题。 – rdurand