Reputation: 1806
i have 60 rows in an table view.i have an array named as "BundleImagesArray " with 60 bundle images names.So i am retrieving the images from bundle and creating thumbnail to it. whenever binding each cell at first time ,i am storing the Thumbnail images in to an array.because of enabling the fast scrolling after bind each cell.i am utilizing the images from the array(without creating the thumbnail again).however the imageCollection array(which will store thumbnail images) is disorder some times
the Index path.row is coming as 1,2.....33,34,50,51..etc
its not an sequential order.so i am getting trouble with my imageCollection array which is used to store and retrieve images according to the index path.may i know what is the reason for that.can any one provide me a good solution for this.is there any way to get the indexpath.row as sequential order?
my cellForRowAtIndexPath code is:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"IndexPath Row%d",indexPath.row);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if ([cell.contentView subviews])
{
for (UIView *subview in [cell.contentView subviews])
{
[subview removeFromSuperview];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setAccessoryType:UITableViewCellAccessoryNone];
Class *temp = [BundleImagesArray objectAtIndex:indexPath.row];
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
importMediaSaveImage.tag=indexPath.row+1;
[cell.contentView addSubview:importMediaSaveImage];
UILabel *sceneLabel=[[[UILabel alloc] initWithFrame:CGRectMake(220,0,200,135)] autorelease];
sceneLabel.font = [UIFont boldSystemFontOfSize:16.0];
sceneLabel.textColor=[UIColor blackColor];
[cell.contentView addSubview:sceneLabel];
//for fast scrolling
if([imageCollectionArrays count] >indexPath.row){
importMediaSaveImage.image =[imageCollectionArrays ObjectAtIndex:indexPath,row];
}
else {
//for start activity indicator
[NSThread detachNewThreadSelector:@selector(showallstartActivityBundle) toTarget:self withObject:nil];
NSData *datas = [self photolibImageThumbNailData:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:temp.fileName ofType:@"png" inDirectory:@"Images"]]];
importMediaSaveImage.image =[UIImage imageWithData:datas];
[imageCollectionArrays addObject:importMediaSaveImage.image];
//to stop activity indicator
[NSThread detachNewThreadSelector:@selector(showallstopActivityBundle) toTarget:self withObject:nil];
}
sceneLabel.text = temp.sceneLabel;
temp = nil;
return cell;
}
Upvotes: 1
Views: 1442
Reputation: 80271
An NSArray
is perfectly fine for UITableView
rows. The rows are ordered, and an array is also ordered, so no problem there.
The problem in your code seems to be that you are using two arrays, one immutable and one mutable. You are adding objects to the mutable array, and so it is not exactly predictable where they will be added (because it is not predictable that the rows are going to be needed in order).
I recommend filling your NSMutableArray
first with [NSNull null]
objects, and then inserting the image at a specific point in the array:
// during initialization
for (int i=0; i<numberOfImages; i++) {
[imageCollectionArrays addObject:[NSNull null]];
}
// in cellForRowAtIndexPath:
[imageCollectionArrays replaceObjectAtIndex:indexPath.row
withObject:importMediaSaveImage.image];
Try that, see if it works.
Upvotes: 0
Reputation: 77291
Getting the tableview to call you in a particular order is not the right solution. You need to be able to provide any cell it needs in any order.
I think the problem is that you are using an array and trying to access indexes that don't exist yet. You could use an NSMutableDictionary for your imageCollectionArrays (instead of NSArray) and store your data there, keyed by row (or NSIndexPath). They you can add or retrieve them in any order.
Upvotes: 1