【问题标题】:Three20 doesn't show website in UIWebViewThree20 不在 UIWebView 中显示网站
【发布时间】:2011-03-22 15:43:59
【问题描述】:

大家好 我有一个基于标签栏的应用程序。在一个视图中,我有一个带有不同 TTTabItems 的 TTTabStrip。除了加载 UIWebViews 之外,一切正常(加载正常的 UIViewControllers)。

在应用委托中我设置了 url 映射:

TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;

TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]]; // default klasse wenn nichts anderes gewählt ist.
[map from:@"tt://test" toViewController:[TestController class]];

测试控制器包含一个 UIWebView。我可以看到 (NSLog) 调用了 loadView-Method,但是 URL 没有被打开:

- (void) loadView {

    CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
    self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
    //self.view.backgroundColor = [UIColor blackColor];

    NSURL *theURL = [NSURL URLWithString:@"http://www.google.com"];
    [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; 

    // support zooming
    webView.scalesPageToFit = YES;
}

例如,我可以将 UIWebView 的背景更改为黑色。

如何在 TTTabStrip 下方的网络视图中加载 google?

非常感谢。

【问题讨论】:

    标签: iphone objective-c uiwebview three20


    【解决方案1】:

    尝试以下方法并添加方法 viewWillAppear:

    - (void)loadView 
    {
        CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
        UIView * newView = [[UIView alloc] initWithFrame:applicationFrame];
    
        // support zooming
        webView.scalesPageToFit = YES;
    
        [newView addSubview:webView];
    
        self.view = newView;
        [newView release];
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        NSURL *theURL = [NSURL URLWithString:@"http://www.google.com"];
        [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; 
    }
    

    【讨论】:

    • 嗨尼克。非常感谢您的回答。您的 loadView 方法已被调用,但 viewWillAppear 方法尚未被触及。这意味着 webview 仍然是灰色的。
    • 这很奇怪。你能在 TestController 的视图中放一些简单的东西,比如标签吗?然后看看有没有显示。应该调用 viewWillAppear。也许 viewDidAppear 被调用? webview的frame你设置了吗?
    • 你是对的。 viewDidLoad 已被调用。我将 viewWillAppear 的内容放入 viewDidLoad 但没有任何反应。奇怪的是,当我尝试加载一个在 IB 中创建的简单 xib 时,它会显示出来。这个webview一定有问题。没有 webView 的框架还没有设置..
    • 我终于明白了。我已经设置了 webView 的框架并且它可以工作。我在 loadView 中添加了这两行: CGRect webFrame = [[UIScreen mainScreen] applicationFrame]; webView = [[UIWebView alloc] initWithFrame:webFrame];非常感谢尼克,你救了我的命:)
    • 不客气 :) 有趣的是,你有多少次偶然发现那些耗费大量时间解决的简单问题。
    猜你喜欢
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    相关资源
    最近更新 更多