在新地图视图中打开地址的属性文本视图

Attributed Text View that opens address in new map view

我正在开发一个使用解析作为后端并允许用户通过文本视图post他们的地址的应用程序。我启用了 "Addresses" 属性并在 Apple 地图应用程序中打开了地址。相反,我想通过打开一个带有地图的新视图并将他们点击的地址固定到地图视图来让我的用户留在我的应用程序中。

有什么方法可以做到这一点而不会使事情变得过于复杂吗?

感谢您的帮助!

您可以实现 UITextViewDelegate 方法:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange;

Description: Asks the delegate if the specified text view should allow user interaction with the given URL in the given range of text.

The text view calls this method if the user taps or long-presses the URL link. Implementation of this method is optional. By default, the text view opens the application responsible for handling the URL type and passes it the URL. You can use this method to trigger an alternative action, such as displaying the web content at the URL in a web view within the current application.

Reference

例如:

  1. 确保您的 class 符合:<UITextViewDelegate>
  2. 设置您的文本视图委托:[textView setDelegate:self];
  3. 实现委托方法:

...

#pragma mark - UITextViewDelegate

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { 
    // Open custom map using data from textView.text. 
}