UIWebView可能导致我的应用程序崩溃?

时间:2013-09-16 11:11:53

标签: ios objective-c uiwebview theos

我正在制作一个没有Xcode的简单应用,在我的iPod上使用Theos,我希望该应用只需加载http://www.google.com/

当我启动应用程序时,屏幕变黑,然后在10秒后崩溃。我相信它与我使用UIWebView有关,但我不确定。我做错了什么吗?我该怎么做才能弄清楚发生了什么?

我有4个文件:
的main.m

int main(int argc, char **argv) {
        NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
        int ret = UIApplicationMain(argc, argv, @"comvlad1kwebApplication", @"comvlad1kwebApplication");
        [p drain];
        return ret;
}

// vim:ft=objc

RootViewController.h

@interface RootViewController: UIViewController {
UIWebView *webview;
}
@end

RootViewController.mm

#import "RootViewController.h"

@implementation RootViewController

- (void)loadView {
    webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 1024,768)];
    NSString *url=@"http://www.google.com";
    NSURL *nsurl=[NSURL URLWithString:url];
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
    [webview loadRequest:nsrequest];
    [self.view addSubview:webview];
}
@end

生成文件

include theos/makefiles/common.mk

APPLICATION_NAME = comvlad1kweb
comvlad1kweb_FILES = main.m comvlad1kwebApplication.mm RootViewController.mm
comvlad1kweb_FRAMEWORKS = UIKit CoreGraphics Foundation

include $(THEOS_MAKE_PATH)/application.mk

1 个答案:

答案 0 :(得分:0)

请改用:

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    webview=[[UIWebView alloc]initWithFrame:self.view.bounds];
    NSString *url=@"http://www.google.com";
    NSURL *nsurl=[NSURL URLWithString:url];
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
    [webview loadRequest:nsrequest];
    [self.view addSubview:webview];
}
@end