【发布时间】:2010-12-22 15:13:53
【问题描述】:
我有一个简单的 UIViewController,只有一个 UIWebView。 UIWebView 应该占用所有可用空间来显示 url 的内容。
我想在不同的地方重用这个 ViewController。在某些情况下,它将被推送到 NavigationController 中,在某些情况下,它将显示为 ModalViewController。有时它可能在 TabBarController 中。 UIWebView 的大小会因情况而异。
不使用 Interface Builder 设置 UIWebView 框架的最佳方法是什么?换句话说,我应该如何在下面的代码中初始化 webViewFrame?还是我还缺少其他东西?
- (void)viewDidLoad {
[super viewDidLoad];
UIWebView* webView = [[UIWebView alloc] initWithFrame:webViewFrame];
webView.delegate = self;
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
}
我尝试了不同的可能性(self.view.frame、self.navigationController.view.frame 等),但似乎没有什么适用于所有情况。
【问题讨论】:
标签: iphone uiviewcontroller uiwebview uinavigationcontroller uitabbarcontroller