2011-09-04 30 views
3
theTweet = [[[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)] autorelease]; 
    theTweet.text = [[tweets objectAtIndex:index] objectForKey:@"text"]; 
    theTweet.dataDetectorTypes = UIDataDetectorTypeLink; 
    [tweetView addSubview:theTweet]; 

[[鳴叫objectAtIndex:指數] objectForKey:@ 「文本」];包含http://t.co/######一個鏈接,但它似乎並不像UITextView的被檢測http://t.co鏈接。我需要使用UIWebView嗎?的UITextView dataDetectorTypes無法檢測http://t.co/鏈接?

+0

是否缺少theTweet.dataDetectorTypes = UIDataDetectorTypeLink; ? – 0x8badf00d

+0

已經在。仍然無法正常工作。 – ninjaneer

回答

3

沒有設置:theTweet.dataDetectorTypes = UIDataDetectorTypeLink; ?

現在你還說,我想這樣的代碼:

UITextView *theTweet; 
theTweet = [[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)]; 
theTweet.text = @"http://t.co/######"; 
theTweet.editable = NO; 
theTweet.dataDetectorTypes = UIDataDetectorTypeLink; 
[myview addSubview:theTweet]; 

,它工作正常我。

錯誤一定在別處。 (你關閉編輯嗎?)

+0

是的,忘了補充一點,在原崗位。還是行不通。 – ninjaneer

+0

將仔細檢查下一個版本。 – ninjaneer

+0

確保您在設備上進行測試,而不是在模擬器上進行測試。 – Henning

4

嘗試使用此希望這對您有所幫助

鏈接是不是默認的的UITextView點擊。但幸運的是,他們可以用代碼簡單的幾行啓用:

theTweet.editable = NO; 
theTweet.dataDetectorTypes = UIDataDetectorTypeLink; 

不幸的是,你不能有一個可編輯的UITextView與可點擊的鏈接。如果您將可編輯設置爲YES,則所有鏈接將被視爲常規文本。

篩選。

UITextView *theTweet= [[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)]; 
theTweet.text = @"http://t.co/######"; 
theTweet.editable = NO; 
theTweet.dataDetectorTypes = UIDataDetectorTypeLink; 
[myview addSubview:theTweet]; 
7

我注意到的一件事是,爲了讓UITextViews識別鏈接,您需要將可選項設置爲YES。例如:

self.bodyTextView = [[UITextView alloc]initWithFrame:myFrame]; 
[self.bodyTextView setEditable:NO]; 
//this is the key 
[self.bodyTextView setSelectable:YES]; 
[self.bodyTextView setDataDetectorTypes:UIDataDetectorTypeLink]; 
[self.bodyTextView setAttributedText:myAttributedText]; 
0

您需要設置可編輯的屬性NO

theTweet = [[[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)] autorelease]; 
theTweet.editable = NO; //add this line 
theTweet.text = [[tweets objectAtIndex:index] objectForKey:@"text"]; 
theTweet.dataDetectorTypes = UIDataDetectorTypeLink; 
[tweetView addSubview:theTweet];