【发布时间】:2015-08-28 18:22:50
【问题描述】:
说明: 我有一个包含 NavigationBar 和 UIWebView 的视图控制器。 webview 在 .m 文件中设置为全屏。在 viewcontroller 上,导航栏排在最前面。
会发生什么:当我运行应用程序时,唯一可见的是 web 视图(全屏),但导航栏不存在。
假设会发生什么:这是不言自明的,但导航栏应该位于顶部,而 webview 位于其下方。
长什么样子
.m 文件
#import "SecondViewController.h"
@interface ViewController2 ()
@end
@implementation ViewController2
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
NSString *url2=@"http://bithumor.co/server/trending/index1.php";
NSURL *nsurl2=[NSURL URLWithString:url2];
NSURLRequest *nsrequest2=[NSURLRequest requestWithURL:nsurl2];
[webview2 loadRequest:nsrequest2];
webview2.scrollView.bounces = NO;
[self.view addSubview:webview2];
@end
.h 文件
#import <UIKit/UIKit.h>
@interface ViewController2 : UIViewController
@end
问题/问题:导航栏不可见,如何解决这个问题,让 webview 和导航栏都可见?
【问题讨论】:
-
你能给我们看看故事板吗?
-
@T_77 编辑了我的问题
-
还向我们展示视图层次结构
-
i.stack.imgur.com/vlrQp.png - 前面是 web 视图
-
只需将 webview2 连接到它在情节提要中的插座,然后使用 self.webview2 loadrequest
标签: ios objective-c uiwebview uinavigationbar