I am trying to load an image from my server in my iOS Today Widget. However, whenever I do that, I get a crash that is because of a "memory error". I think it might be because I programmatically create the UIImageView
, but then again that might not be the answer because loading a local image works fine. Is there a way to reduce the memory size while loading it?
In tableviewcell.m
:
self.picct = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
self.picct.backgroundColor = [UIColor clearColor];
[self addSubview:self.picct];
In Today Widget Table View:
cell.picct.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.mywebsite.com/%@.jpg", [itemAtIndex objectForKey:@"myimagename"]]]]];
[cell.picct release];
Widget only can use 10MB(not documented, just guessed value from my experiments) memory due to prevent unload apps in background.