当用户单击非我的应用程序的按钮时,它将加载另一个包含web视图的视图。但是,导航不会显示在web视图中。有什么建议吗?
以下是我用来在web视图中加载的代码:
- (IBAction)visiteSite:(id)sender {
WebViewController *hospitalSite = [self.storyboard instantiateViewControllerWithIdentifier:@"hospitalSite"];
hospitalSite.hospitalWebURL = self.url;
[self presentViewController:hospitalSite animated:YES completion:nil];
}
在Web视图上,我使用它来加载实际内容并生成导航栏:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIWebView *webView = [[UIWebView alloc] init];
webView.frame = self.view.frame;
[webView loadRequest:[NSURLRequest requestWithURL: self.hospitalWebURL]];
[webView setScalesPageToFit:YES];
[[self view] addSubview:webView];
webView.clipsToBounds =YES;
webView.frame = CGRectMake(0,64,webView.frame.size.width,webView.frame.size.height-64);
self.navigationController.navigationBar.alpha = 0.8f;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:
[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[UIViewController alloc]
initWithNibName:@"hospitalSite" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
//Navigation controller init with ViewController as root
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
网站在网页视图中加载,但我只是在顶部有一个空的白色栏,而不是导航栏。
有什么建议吗?
您的意思是将控制器呈现为模态吗?也许应该按以下方式推进?:
- (IBAction)visiteSite:(id)sender {
WebViewController *hospitalSite = [self.storyboard instantiateViewControllerWithIdentifier:@"hospitalSite"];
hospitalSite.hospitalWebURL = self.url;
[[self navigationController] pushViewController:hospitalSite animated:YES];
}
此外,您可能希望在viewWillAppear或viewDidPear而不是viewDidLoad中执行与框架相关的代码,以便所有视图布局都已发生。否则,某些框架尺寸可能是错误的。