tba*_*bag 2 objective-c nsstring uitextview ios
我的代码中有以下几行,用于向UITextView添加可点击的URL.merchantwebsite是我的UITextView.
self.merchantwebsite.attributedText = [[NSAttributedString alloc] initWithString:@"http://www.crossfit.com" attributes:@{NSLinkAttributeName: @"http://www.crossfit.com"}];
self.merchantwebsite.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
当我单击UITextView时,应用程序会与日志崩溃
2014-03-19 16:13:43.051 BTLE[27103:60b] -[__NSCFConstantString scheme]: unrecognized selector sent to instance 0x1a4404
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我做错了什么.
谢谢!
您显然拥有希望URL为NSURL的代码.但是,很简单,NSString 不是 NSURL.试试这样:
self.tv.attributedText =
[[NSAttributedString alloc]
initWithString:@"http://www.crossfit.com"
attributes:
@{NSLinkAttributeName: [NSURL URLWithString:@"http://www.crossfit.com"]}];
Run Code Online (Sandbox Code Playgroud)