2013-04-15 53 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