It looks like you're new here. If you want to get involved, click one of these buttons!
MainTableCells *cell = [theTable dequeueReusableCellWithIdentifier:@\"customCell\"];
if (cell == nil)
{
cell = [[[MainTableCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@\"customCell\"] autorelease];
tablerow++;
NSLog(@\"alloc tablecell\");
}
if (indexPath.row == 0)
{
// [[cell dynamicText] setTag:1];
[[cell firstImage] setTag:1];
[[cell secondImage] setTag:2];
[[cell thirdImage] setTag:3];
[[cell fourthImage] setTag:4];
} else if (indexPath.row == 1)
{
[[cell firstImage] setTag:5];
[[cell secondImage] setTag:6];
[[cell thirdImage] setTag:7];
[[cell fourthImage] setTag:8];
} else if (indexPath.row == 2)
{
[[cell firstImage] setTag:9];
[[cell secondImage] setTag:10];
[[cell thirdImage] setTag:11];
[[cell fourthImage] setTag:12];
}else if (indexPath.row == 3)
{
[[cell firstImage] setTag:13];
[[cell secondImage] setTag:14];
[[cell thirdImage] setTag:15];
[[cell fourthImage] setTag:16];
} else if (indexPath.row == 4)
{ [[cell firstImage] setTag:17];
[[cell secondImage] setTag:18];
[[cell thirdImage] setTag:19];
[[cell fourthImage] setTag:20];
} else if (indexPath.row == 5)
{
[[cell firstImage] setTag:21];
[[cell secondImage] setTag:22];
[[cell thirdImage] setTag:23];
[[cell fourthImage] setTag:24];
} else if (indexPath.row == 6)
{
[[cell firstImage] setTag:25];
[[cell secondImage] setTag:26];
[[cell thirdImage] setTag:27];
[[cell fourthImage] setTag:28];
} else if (indexPath.row == 7)
{
[[cell firstImage] setTag:29];
[[cell secondImage] setTag:30];
[[cell thirdImage] setTag:31];
[[cell fourthImage] setTag:32];
}
//NSLog(@\"table count %d\",indexPath.row);
// if ([didFill isEqualToString:@\"no\"])
//{
//for (NSString *key in thumblist)
//{
//if (tablerow > [thumblist count] || tablerow == [thumblist count]) { break;}
// if (tablerow == 0 || tablerow == 4 || tablerow == 8 || tablerow == 12 || tablerow == 16 || tablerow == 19 || tablerow == 23 || tablerow == 26 || tablerow == 29){
if ([thumblist objectAtIndex:tablerow] != nil)
{
NSURL *firstImageURL = [NSURL URLWithString:[thumblist objectAtIndex:tablerow]];
NSData *firstImageData = [[NSData alloc] initWithContentsOfURL:firstImageURL];
UIImage *firstImage = [[UIImage alloc] initWithData:firstImageData];
[[cell firstImage] setBackgroundImage:firstImage forState:UIControlStateNormal];
[firstImage release];
[firstImageData release];
}
//}
if (tablerow < ([thumblist count]-1))
{
tablerow++;
}
NSLog(@\"table image count %d\", tablerow);
// if (tablerow == 1 || tablerow == 5 || tablerow == 9 || tablerow == 13 || tablerow == 17 || tablerow == 20 || tablerow == 24 || tablerow == 27 || tablerow == 30){
if ([thumblist objectAtIndex:tablerow] != nil)
{
NSURL *secondImageURL = [NSURL URLWithString:[thumblist objectAtIndex:tablerow]];
NSData *secondImageData = [[NSData alloc] initWithContentsOfURL:secondImageURL];
UIImage *secondImage = [[UIImage alloc] initWithData:secondImageData];
[[cell secondImage] setBackgroundImage:secondImage forState:UIControlStateNormal];
[secondImage release];
[secondImageData release];
}
//}
if (tablerow < ([thumblist count]-1))
{
tablerow++;
}
//if (tablerow == 2 || tablerow == 6 || tablerow == 10 || tablerow == 14 || tablerow == 18 || tablerow == 21 || tablerow == 25 || tablerow == 28 || tablerow == 31){
if ([thumblist objectAtIndex:tablerow] != nil)
{
NSURL *thirdImageURL = [NSURL URLWithString:[thumblist objectAtIndex:tablerow]];
NSData *thirdImageData = [[NSData alloc] initWithContentsOfURL:thirdImageURL];
UIImage *thirdImage = [[UIImage alloc] initWithData:thirdImageData];
[[cell thirdImage] setBackgroundImage:thirdImage forState:UIControlStateNormal];
[thirdImage release];
[thirdImageData release];
}
// }
if (tablerow < ([thumblist count]-1))
{
tablerow++;
}
// if (tablerow == 3 || tablerow == 7 || tablerow == 11 || tablerow == 15 || tablerow == 19 || tablerow == 22 || tablerow == 26 || tablerow == 29 || tablerow == 32){
if ([thumblist objectAtIndex:tablerow] != nil)
{
NSURL *fourthImageURL = [NSURL URLWithString:[thumblist objectAtIndex:tablerow]];
NSData *fourthImageData = [[NSData alloc] initWithContentsOfURL:fourthImageURL];
UIImage *fourthImage = [[UIImage alloc] initWithData:fourthImageData];
[[cell fourthImage] setBackgroundImage:fourthImage forState:UIControlStateNormal];
[fourthImage release];
[fourthImageData release];
}
// }
if (tablerow < ([thumblist count]-1))
{
tablerow++;
}
NSLog(@\"nums %d\", tablerow);
//NSLog(@\"Did update %@\", didUpdate);
//NSLog(@\"image num %d:\", tablerow);
/* if (tablerow < ([thumblist count]-1)) {
tablerow++;
} else if (tablerow == ([thumblist count]-1) || tablerow >= ([thumblist count]-1)) {didFill=@\"yes\"; NSLog (@\"break...\"); break;}
if (negate == 1) { negate = 4; break; } else { negate--; }*/
// NSLog(@\"Negation: %d\",negate);
//}
//}
if ([didUpdate isEqualToString:@\"NO\"])
{
//[self populateTable];
//NSLog(@\"Description %@\", [thumblist description]);
didUpdate =@\"YES\";
}
return cell;
Replies
Absolutely, 100%, the wrong approach. Never do this again.
Ah yes, nothing makes a forum post easy to read like including tons of commented out code. Auto-color coding is a feature of Xcode. I'm not looking at Xcode right now, am I?
You can't have nil in an array, so this is pointless.
As for the rest... dear lord you seem to like making things hard on yourself.
You want to do the work in preparing your data array. You want to remove the work from your table delegate methods. There are several approaches. One would be to make an array of arrays of image names. Ex:
So here in cellForRow when you are ready to grab images, you'd approach it like so:
Much easier. However, there will be a problem if the total number of images is not a multiple of 4. You'll need to do a lot of range checking on the imageNames array before trying to grab any image. An alternative that might be a bit safer would be to use dictionaries instead:
Same idea to extract:
If the name isn't there, you'll get back nil, so you won't create an image, so you'll have a built-in bonus of automatically clearing out unused image views.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere is how I setup the array
Here is cellforrowatindex
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf these images are being downloaded, that's why your scrolling is choppy. Worse, you're downloading at least some of the images multiple times if the user scrolls up and down.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome