{"id":3452,"date":"2014-03-25T11:25:13","date_gmt":"2014-03-25T11:25:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/25\/nsthread-uitableviewcell-and-image-collection-of-common-programming-errors\/"},"modified":"2014-03-25T11:25:13","modified_gmt":"2014-03-25T11:25:13","slug":"nsthread-uitableviewcell-and-image-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/25\/nsthread-uitableviewcell-and-image-collection-of-common-programming-errors\/","title":{"rendered":"NSThread, UITableViewCell and Image-Collection of common programming errors"},"content":{"rendered":"<p>i am currently having some problem with my UITableView, this is the first time I am putting thumbnail in my table view cell and also integrating NSThread to load thumbnail image, so, please bare with me. Thanks<\/p>\n<p>I am downloading the data and setting up the cells like usual, but this time with the NSThread added.<\/p>\n<p>First I will call ASIHTTPRequest in my view did load<\/p>\n<p>Then in &#8211; (void)requestFinished:(ASIHTTPRequest *)request I will add the url of the thumbnail into an NSMutableArray<\/p>\n<pre><code> NSString *photoURLString = [NSString stringWithFormat:@\"http:\/\/some.url.com\/img\/%@\",[thearray objectForKey:@\"tn_url\"]];    \n[thumbNailURL addObject:(photoURLString)];\n<\/code><\/pre>\n<p>And in the cellForRowAtIndexPath: where I am setting up other data to display, I will call my NSThread<\/p>\n<pre><code>[NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:indexPath];\n<\/code><\/pre>\n<p>And in my loadImage thread<\/p>\n<pre><code>- (void) loadImage: (NSIndexPath*) indexPath{\nNSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\nNSString *iconURL = [thumbNailURL objectAtIndex:indexPath.row];\nNSURL *url = [NSURL URLWithString:iconURL]; \nUIImage *icon = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];\ncellImageView = [[UIImageView alloc] initWithFrame:CGRectMake(11.0, 6.0, 61.0, 50.0)];\n[cellImageView setImage:icon];\nUITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];\n[cell.contentView performSelectorOnMainThread:@selector(addSubview:) withObject:cellImageView waitUntilDone:NO];\n[pool drain];\n<\/code><\/pre>\n<p>}<\/p>\n<p>All the data and image loaded just fine, but if I scroll faster up and down , the application will hang with the following error<\/p>\n<pre><code>[1997:7a1f] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]'    (0x31312d2f 0x345f50e3 0x3127d1b1 0x35aefc1d 0xf4dd 0x333ffb51 0x3347c67b 0x366af589 0x366b2310) terminate called throwing an exceptionProgram received signal:  \"SIGABRT\".\n<\/code><\/pre>\n<p>It would be great if anyone could show me the correct configuration if I am wrong, as I have been trying different approches for the past 3 days already. Thank you so much.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i am currently having some problem with my UITableView, this is the first time I am putting thumbnail in my table view cell and also integrating NSThread to load thumbnail image, so, please bare with me. Thanks I am downloading the data and setting up the cells like usual, but this time with the NSThread [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3452","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3452"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3452\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}