English 中文(简体)
缩略语 观点
原标题:multiple UIWebView-s on a UIScrollView

I m experimenting with a magazine kind of iPad app that I develop and I ran into a memory issue. There are multiple UIWebView-s on a UIScrollView. Every UIWebView displays an html page each from html file source. Unfortunately I couldn t find the solution to handle the web views to load them smoothly in the background once the app loaded, instead of that it loads and fires every html pages with all its javascripts and images, because I want them to be visible once I swipe through on them, hovewer I get "Received memory warning" message at 30 panels and the app breaks.

我用来展示网络看法的守则是:

NSInteger numberOfViews = 47;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat yOrigin = i * 768;
    DetailViewController *detailViewController2 = [[DetailViewController alloc] initWithNibName:@"Detail" bundle:nil];

    [detailViewController2.view setFrame:CGRectMake(yOrigin, 0, 768, 1024)];
    detailViewController2.view.clipsToBounds = YES;
    [scroll.view insertSubview:detailViewController2.view atIndex:0];        
}

scroll.scrollView.contentSize = CGSizeMake(768 * numberOfViews,1004);
scroll.pageControl.numberOfPages = numberOfViews;

self.view.clipsToBounds = YES;
self.view.clearsContextBeforeDrawing = YES;
CGRect frame;
frame.origin.x = scroll.scrollView.frame.size.width * scroll.pageControl.currentPage;
frame.origin.y = 0;
frame.size = scroll.scrollView.frame.size;
[scroll.scrollView scrollRectToVisible:frame animated:NO];
self.scrollViewController = scroll;
[self.view insertSubview:scroll.view atIndex:0];

- (void)dealloc {
    [scrollViewController release];
    [tableOfContentsViewController release];

    [portrait release];
    [tableOfContents1 release];
    [start release];

    [super dealloc];
}

显示html内容的法典载于DetaildViewController:

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:htmlfilename 
                                                         ofType:@"html" 
                                                    inDirectory:@"/htdocs" ];

    NSString *html = [NSString stringWithContentsOfFile:htmlPath 
                                               encoding:NSUTF8StringEncoding 
                                                  error:nil];

    web.delegate = self;
    [web setMultipleTouchEnabled:YES];
    [web loadHTMLString:html 
                baseURL:[NSURL fileURLWithPath:
                         [NSString stringWithFormat:@"%@/htdocs/", 
                          [[NSBundle mainBundle] bundlePath]]]];

- (void)dealloc {
    //---release the memory used by the property---
    [page release];


    [web setDelegate:nil];
    [web stopLoading];
    [web release];


    [orientation release];
    [page release];

    [super dealloc];
}

问题在于,我如何能够顺利地把他们装在《联合国国际数据集》的背部,而且,一旦小组向观察所投放,我计划用其html页显示60多份网站概览,我只能向该报社开火?

最佳回答

You need to recycle your views. Creating a bunch of views when only one at a time will ever be visible is not a good strategy. Apple has a few lengthy video tutorials on the subject. The basic idea is to use at most 3 or 4 views (UiWebViews). As you swipe and the view bounds become visible you initialize it. When it s no longer visible you destroy it. The Wall Street Journal iPad & iPhone app uses a similar pattern. Here s link to a few resources & tutorial: Are there any good UIScrollView Tutorials on the net?

问题回答

暂无回答




相关问题
How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

What should I load into memory when my app loads?

I have objects I am saving to the file system using serialization. When I load the app, should I load all the objects into memory or just stubs (for searching capabilities)? If I load just stubs, ...

Data Destruction In C++

So, for class I m (constantly re-inventing the wheel) writing a bunch of standard data structures, like Linked Lists and Maps. I ve got everything working fine, sort of. Insertion and removal of ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

View ram in DOS

Is there a way in dos (im using a dos boot disk on a linux machine) to view portions of ram? ie. some form of command to read the binary at a given address? edit: my bootable floppy doesnt have ...

does argument in printf get located in memory?

in c, when I write: printf("result %d ",72 & 184); Does "72 & 184" get a a block in memory (for example 72 takes 4 bytes, 184 takes 4 bytes?...)

热门标签