且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将click事件添加到ios NSString中的某些文本

更新时间:2023-09-29 18:56:04

如果您使用值字段传入目的地该怎么办?

What if you used the value field to pass in the destination?

[attributedString addAttribute:NSLinkAttributeName
                         value:[@"destinationController1" stringByAppendingString:username]
                         range:range];

然后覆盖委托方法:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
    if ([URL.scheme isEqualToString:@"destinationController1"]) {
        // Launch View controller
        return NO;
    }
    return YES;
}