ios - 从另一个 View 将请求加载到 Web View 中

标签 ios objective-c

在我的 iPhone (iOS 5/6) 应用程序的一部分中,我有一系列按钮可以在我的应用程序中打开一个 URL(目前通过移动 Safari 的 URL 方案)。我不希望制作单独的 View Controller ,每个 View Controller 在每次按下按钮时都充当模态。

与其拥有 5 个不必要的 View Controller ,不如制作一个 .xib 文件作为应用程序范围的 Web View 。 IE:当用户按下一个按钮时,与该按钮对应的 URL 将在此新 View 中打开(假设它称为 WebViewController)。

用伪代码或只是一个解释,你能解释一下我应该怎么做吗?关于这个特定问题的在线/书籍很少。

最佳答案

您必须创建一个单独的 View Controller ,该 Controller 将附加一个 UIWebView socket 。创建一个使用 URL 参数初始化该 View Controller 的方法,并将其加载到 UIWebView 中。是吗?

还有一些伪代码,因为你要求它:

// SomeControllerWithinTheApp.m
- (IBAction)myWebsiteLinkTapped {
  MyWebController *viewController = [[MyWebController alloc] initWithURL:kWebsiteURL];
  // show it modally or push, up to you
}

// SomeOtherControllerWithinTheApp.m
- (IBAction)someLinkButtonTapped {
  MyWebController *viewController = [[MyWebController alloc] initWithURL:kSomeOtherURL];
  // show it
}

MyWebController-viewDidLoad 方法上加载使用传递的 url 创建的 URLRequest 并将其加载到您的 Web View 中。

关于ios - 从另一个 View 将请求加载到 Web View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15181385/

相关文章:

objective-c - NSRunningApplication 没有特定的应用程序窗口

iphone - UITableViewCell 中的 UITextView

ios - 即使在加载 url 后,UIWebview 仍显示空白屏幕

ios - 如何从 UITextField 获取 UITableViewCell 的索引?

ios - 什么时候textFieldDidEndEditing :textField be called?

ios - Ionic 应用程序和键盘在 iOS 上放大/变大

android - ionic 3 : storage in both IndexedDB and Web SQL

ios - 使用 Geocoder 更新属性以获取用户实际地址,EXC_BAD_ACCESS

ios - UIImageView - 如何获取分配的图像的文件名?

ios - 如何允许对 uiwebview 上的操作发出 javascript 警报