0

I'm working on a project. I've implemented expandable cell , I have some information on the cell and when I click it it expands showing a description. Im loading the description in a UIWebView as I'm taking it in html format from JSON.

What I'm having trouble is that the scroll in UITableView is lagging, and Im 99% sure it is the UIWebView causing the problem as I have other tableviews as well with non-expandable cells , and they're scrolling all smooth.

I think I might solve the problem by not letting the table at the beginning load the html content , only loading it on the Didselect method for each cell I select.

But I'm having a hard time accomplishing this.Is there anyway I can load the UIWebView only for 1 specific cell (in this case only the cell I click). Any help is appreciated. If u think there's another way to solve this problem feel free to give suggestions.

Thanks in advance

PS: I've looked at the expandable cell tutorial for swift in youtube and made more or less the same.

Pratik Shah
  • 563
  • 4
  • 14
  • Is it possible to load your content as an Attributed String? Because a WebView will be always slow while scrolling. Other idea is, that you load your content, make an Screenshot from your Content, and use the image instead of an WebView. – derdida Dec 10 '15 at 12:49
  • I need the links to be clickable and the text shouldn't be editable , u can only view it. – goldborn.dushi Dec 10 '15 at 12:57
  • This is still possible with attributed Strings: http://stackoverflow.com/questions/21629784/make-a-clickable-link-in-an-nsattributedstring-for-a-uitextfield-or-uilabel – derdida Dec 10 '15 at 12:59

3 Answers3

2
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
NSData* data = [NSData dataWithContentsOfURL:@"YOUR URL"];
dispatch_async(dispatch_get_main_queue(), ^(void){
    //Run UI Updates
    [mWebView loadData:data MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil];
});
});
vaibby
  • 1,255
  • 1
  • 9
  • 23
0

use GCD it will take UIWebview loading process in background and load UIWebview when loading is complte

vaibby
  • 1,255
  • 1
  • 9
  • 23
  • I use GCD , but it's not the process that is making the whole problem , content loaded and staying in the uiwebview is causing the lag. I need it empty and load only when I click on the cell. – goldborn.dushi Dec 10 '15 at 13:28
  • in didSelectRowAtIndexPath add UIWebview in cell subview and loadURLRequest and show activity until fully load – vaibby Dec 10 '15 at 14:26
0

Ok Guys vaibby was right. Thanks all for the responses.

I used GCD but it was called in the wrong place. Just wanted to let you know that the problem is solved. What I did was as a first step cached the images of the UItableView. As a second step and very important one I implemented the Async library into my project , and used it at the cellForRowAtIndexPath function to call the webView in the Async.background (so it draws the UIwebView in a back thread) , now the scrolling is working as it should.