iphone - I get didreceivememorywarning uitableview usuing AFNetworking to download the images? -


hello have uitableview use afnetworking load large images. when didreceivememorywarning hit app crashes. here code :

in afnetworking+uiimageview.m have added suggested :

@implementation afimagecache  - (id)init {     self = [super init];     if (self) {         [[nsnotificationcenter defaultcenter] addobserver:self                                                  selector:@selector(didreceivememorywarning)                                                      name:uiapplicationdidreceivememorywarningnotification                                                    object:nil];     }     return self; }  - (void)didreceivememorywarning {     debuglog(@"afnetworking did received memory warning ");     [self removeallobjects]; } 

and code in uitableview follows :

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath         touscell *tvcell;         nsarray *nib;         nib = [[nsbundle mainbundle] loadnibnamed:@"touscell" owner:self options:nil];         tvcell = [nib objectatindex:0];          tvcell.lbltitle.text=[[dict valueforkey:@"message"]objectatindex:i];  [tvcell.imgphoto setimagewithurl:[nsurl urlwithstring: [nsstring stringwithformat:@"http://test.com/%@", [[dict valueforkey:@"photo"]objectatindex:i]]]]; 

may recreating cells each , everytime? sure linked images download images v large ( in size 2 - 3 mb?).

you're recreating table cell each time if images different take lot of space. must reuse table view cells as possible using

[tableview dequereusablecellwithidentifier:] 
method , registering nib in view controller view did load using the:

[tableview registernib:forcellreuseidentifier:] 

method.

also note if images large, afnetworking offers possibility downsize them before returning caller. useful if need fit large image on small cell (e.g. 1 table view). note afnetworking doesn't provide resizing functions returns image in 2 different blocks: 1 before post-processing , 1 after post-processing.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -