我无法在UIAlertController中单击超链接。我想在超链接上单击打开外部浏览器。
-(void)viewDidAppear:(BOOL) animated {
NSString *htmlString = @"Welcom to AlertView for more information <A href=\"https://www.google.com\"> Click Here </A>";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""
message:htmlString
preferredStyle:UIAlertControllerStyleAlert];
NSAttributedString *attributedStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
documentAttributes:nil error:nil];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
// OK button tappped.
[self dismissViewControllerAnimated:YES completion:^{ }];
}];
[alert setValue:attributedStr forKey: @"attributedMessage"];
[alert addAction:defaultAction];
[self presentViewController:alert animated:true completion:nil];
}
单击“单击此处”,然后应打开外部浏览器。是否可以在UIAlertView中获得超链接单击操作?
我认为有可能,但我认为Apple准则并不建议这样做。相反,您应该使用两个按钮“确定”和“不,谢谢”来设置标题“欢迎使用此AlertView,有关更多信息,请访问我们的网站”。用户过去通常单击本地按钮而不是警报控制器中的文本。希望对您有所帮助。
我认为最好添加一个默认的操作按钮,也许标题为“ More info”,它将用来打开URL,但是您可以看一下此same question。