在我的 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/