2013-04-29 34 views
1

我向OHAttributedLabel中的屬性字符串添加URL(「忘記了密碼」鏈接到www.xxx.com「)除了當我點擊該字符串時,沒有任何事情發生。將網址添加到OHAttributedLabel,但不應調用以下鏈接代理

應該在Safari中打開該網址。然後當我試圖添加委託方法。

-(BOOL)attributedLabel:(OHAttributedLabel*)attributedLabel shouldFollowLink:(NSTextCheckingResult*)linkInfo 

此委託方法是不是在所有調用。委託設置正確,因爲我試過其他的委託方法它正在工作

-(UIColor*)attributedLabel:(OHAttributedLabel*)attributedLabel colorForLink:(NSTextCheckingResult*)linkInfo underlineStyle:(int32_t*)underlineStyle; 

我通過接口生成器設置UILabel並將其類更改爲OHAtrributedLabel。這裏是我的代碼

//forgotLabel.text is "Forgot Password" 
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:forgotLabel.text]; 

    [attr setLink:[NSURL URLWithString:@"http://www.yahoo.com"] range:NSMakeRange(0, attr.length)]; 

    //forgotLabel is OHAttributedLabel 
    forgotLabel.attributedText = attr 
    forgotLabel.delegate = self; 

有人可以幫忙嗎?我不想使用TTTAttributedLabel,因爲在我的項目中,我在表格單元格中使用了OHAttributedLabel,並且它完美地工作。所以我不想添加另一個幾乎完全相同的第三部分組件。

在此先感謝。

回答

2

加入

forgotLabel.catchTouchesOnLinksOnTouchBegan = YES; 
我這解決了我自己