2

我有一个应用程序,它基本上是一个 TabBar,其中的选项卡是 UINavigationControllers,它在包含 UIWebViews 的不同 ViewControllers 之间来回移动。我的问题是,虽然我可以单击 UIWebViews 的按钮,但当内容大于屏幕时,我无法滚动内容。

正在创建 TabController

tabBarController = [[MainTabBarController alloc] init];
[tabBarController setDelegate:self];

在选项卡之间切换时,我有以下代码:

WebViewController *wvc = [[WebViewController alloc] initWithNibName:@"WebController" bundle:nil];
UIWebView *wv = [[UIWebView alloc] init];

[wv setUserInteractionEnabled:YES];
[wvc setTitle:[nc title]];
[wv setDelegate:self];
[wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:requestURL]]];
[wvc setWebpage:wv];
[wvc setView:wv];
[nc pushViewController:wvc animated:NO];
NSLog(@"NC.viewcontroller count: %d", [nc.viewControllers count]);
[nc setLastURL:requestURL];
[wvc startLoaderIndicator];

[wv release];
[wvc release];
requestOk = YES;

当点击其中一个 UIWebViews 中的链接时,我有这个:

ItemNavigationController *nc = (ItemNavigationController *)[tabBarController selectedViewController];
WebViewController *wvc = [[WebViewController alloc] initWithNibName:@"WebController" bundle:nil];
UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
//wvc.view = wvc.sView;
[wvc setTitle:[nc title]];
[wv setDelegate:self];
[wv loadRequest:request];
[wvc setWebpage:wv];
[wvc setView:wv];
[nc pushViewController:wvc animated:NO];
NSLog(@"NC.viewcontroller count: %d", [nc.viewControllers count]);
[nc setLastURL:request.URL.absoluteString];
[wvc startLoaderIndicator];

[wv release];
[wvc release];
requestOk = YES;

一切正常,除了 WebViews 不滚动。它看起来像这样: 截屏

这些页面不会滚动

4

3 回答 3

0

创建WebViewController类并在 .m 中viewDidLoad添加:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    [wv setDelegate:self];
     NSURL*url = [NSURL URLWithString:@"http://www.link.com/twitter_iPhone.php"];
    [wv loadRequest:[NSURLRequest requestWithURL:url]];
    [self.view addSubview:wv];
}
于 2012-07-12T09:29:20.837 回答
0

我不喜欢这个代码块的第一件事......

WebViewController *wvc = [[WebViewController alloc] initWithNibName:@"WebController" bundle:nil];
UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
wvc.view = wvc.sView;

而是创建子视图并将其添加到viewDidLoad视图控制器块中的视图。此外,利用 IB 并通过 XIB 添加 WebView 并简单地连接 IBOutlet 和委托。

如果您坚持这样做,请不要覆盖视图,

[wvc.view addSubview:wv];

我在一个简单的 WebViewController 中写了这个:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;

    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    webView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:webView];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://news.google.com"]]]; 
}

并像这样从 AppDelegate 调用它:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];

    CPWebController *webController = [[CPWebController alloc] init];

    CPNavController *navController = [[CPNavController alloc] initWithRootViewController:webController];
    [self.window addSubview:navController.view];

    [self.window makeKeyAndVisible];
    return YES;
}

它的大小正确,有一个导航栏,并且可以正确滚动。为了代码简洁,请原谅缺少发布。

于 2012-07-12T09:58:49.417 回答
0

据我所知,您在这里将其设置为固定高度:

UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,**480**)];

所以内容大小只有 480,所以无处可滚动。尝试类似 (0,0,320, 1000 ); 测试这是否是问题如果是这样,将高度设置为 cotent 大小,以便它是动态的

于 2012-07-12T10:10:18.540 回答