解决方案 »

  1.   

    - (IBAction)switchWebView:(id)sender {
        [view stopLoading];
        [view setHidden:YES];
        UIWebView* webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 80, 320, 480)];
        webView.delegate = self;
        webView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        webView.suppressesIncrementalRendering = YES;
        webView.opaque = YES;
        [self.view addSubview:webView];
        NSURL *objUrl = [NSURL URLWithString:@"http://www.tudou.com/"];
        NSURLRequest *request = [NSURLRequest requestWithURL:objUrl];
        [webView loadRequest:request];
        
        view = webView;
    }程序里就有一个按钮,点击创建一个webview,之前的隐藏,创建4个就崩溃了   报内存警告了
      

  2.   

    你把创建UIWebView的代码写到这个button事件中,也就是在每次点击这个button按钮的时候都会去创建一遍uiwebview. webview被添加到view上后,只有当view被释放时,才会被释放。正确的做法是在viewDidLoad中来创建uiwebview,在整个控制器的生命内只有这一个实例。在点击button时修改webview请求的url地址,伪代码 UIWebView *webView;
    -(void)viewDidLoad {
          [super viewDidLoad];
         webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 80, 320, 480)];
        webView.delegate = self;
        webView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        webView.suppressesIncrementalRendering = YES;
        webView.opaque = YES;
        [self.view addSubview:webView];
    }- (IBAction)switchWebView:(id)sender {
           NSURL *objUrl = [NSURL URLWithString:@"http://www.tudou.com/"];
        NSURLRequest *request = [NSURLRequest requestWithURL:objUrl];
        [webView loadRequest:request];
    }
      

  3.   

    内存问题,自身webview内存处理就存在释放问题,你还多个创建,内存吃不消