2014-09-17 3 views
2

안녕하세요 (20)보다 크고 내 app..If 내 배열 카운트 값 UICollectionView을 구현 내가 이전 datas를 도시하지 않은 도면 ,, cellForItemAtIndexPath에서UICollectionview의 datas 로딩 문제

스크롤을 시도 할 때 (NSIndexPath *) indexPath 방법 난 매번 10 ... datas를 다운로드 수

if (indexPath.row == [recipeImages count] - 1) 
{ 
    [self loadDatas]; 

}

method.So를 확인할 때마다

-(UICollectionViewCell *)collectionView:(UICollectionView*)collectionViewcellForItemAtIndexPath:(NSIndexPath *)indexPath 

    { 
static NSString *identifier = @"CourseList"; 

NSLog(@"indexpath %@ in cell for row",indexPath); 
CollectionCellContent *cell = (CollectionCellContent*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 
NSDictionary *course; 
course=[courselist objectAtIndex:indexPath.row]; 
cell.coursename.text=[course objectForKey:@"course_name"]; 
cell.authorname.text=[course objectForKey:@"course_author"]; 
cell.price.text=[course objectForKey:@"course_price"]; 
cell.cover.image=[UIImage imageNamed:[course objectForKey:@"course_cover_image"]]; 
cell.review.image=[UIImage imageNamed:[course objectForKey:@"ratings"]]; 
NSString *imageUrlString = [[NSString alloc]initWithFormat:@"%@/%@/%@",delegate.course_image_url,[course objectForKey:@"course_id"],[course objectForKey:@"course_cover_image"]]; 

UIImage *imageFromCache = [self.imageCache objectForKey:imageUrlString]; 

if (imageFromCache) { 
    cell.cover.image= imageFromCache; 

} 
else 
{ 
    cell.cover.image = [UIImage imageNamed:@"placeholder"]; 


    [self.imageOperationQueue addOperationWithBlock:^{ 
     NSURL *imageurl = [NSURL URLWithString:imageUrlString]; 
     UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageurl]]; 

     if (img != nil) { 


      [self.imageCache setObject:img forKey:imageUrlString]; 


      [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 

       CollectionCellContent *updateCell = (CollectionCellContent*)[self.ipadcollection cellForItemAtIndexPath:indexPath]; 




       if (updateCell) { 

        [updateCell.cover setImage:img]; 
       } 
      }]; 
     } 
    }]; 
} 


if (indexPath.row == [courselist count] - 1) 
    [self loadDatas]; 
return cell; 

} 부하 datas 방법에서

: [categorylist의 addObject : arrayList1 objectForKey "CATEGORY_NAME"@]; [category_tableView reloadData];

은 내가

-(void)loadDatas 
    { 
    NSString *urltemp=[[databaseurl sharedInstance]DBurl]; 
NSString *[email protected]"AllCourse.php"; 

NSString *URLString=[NSString stringWithFormat:@"%@%@?offset=%d",urltemp,url1,offset]; 

NSMutableArray *search = [du MultipleCharacters:URLString]; 

NSDictionary* menu = [search valueForKey:@"serviceresponse"]; 

NSArray *Listofdatas=[menu objectForKey:@"Course List"]; 
NSMutableArray *temp1=[[NSMutableArray alloc]init]; 

if ([Listofdatas count]>0) 
{ 


    for (int i=0;i<[Listofdatas count];i++) 
    { 
     NSDictionary *arrayList1= [Listofdatas objectAtIndex:i]; 
     NSDictionary* temp=[arrayList1 objectForKey:@"serviceresponse"]; 
     //   NSLog(@"Received Values %@",temp); 
     if (offset==0) { 
      [courselist addObject:temp]; 
     } 
     else 
     [temp1 addObject:temp]; 


    } 


    if (offset!=0) 
    { 


    NSMutableArray *arrayWithIndexPaths = [NSMutableArray array]; 

    for (NSInteger index =courselist.count; index < (courselist.count + temp1.count); index++) { 
     [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:index inSection:0]]; 
    } 

    if (courselist) { 
     [courselist addObjectsFromArray:temp1]; 
     [self.ipadcollection performBatchUpdates:^{ 
      [self.ipadcollection insertItemsAtIndexPaths:arrayWithIndexPaths]; 

     } 

             completion:nil]; 
     // [self.collectionView reloadData]; 

    } 
    else { 
     courselist = [[NSMutableArray alloc] initWithArray:temp1]; 


    } 
    } 
    if (![HUD isHidden]) { 
     [HUD hide:YES]; 
    } 

} 
offset+=10; 
[self.ipadcollection reloadData]; 

}

+0

'downloaddatas' 메소드도 추가 할 수 있습니까? –

+0

아무 도움이 필요합니다 – Tommy

답변

3

이 UICollectionView를 다시로드하기 전에 약간의 지연을 확인 데이터를 다시로드 방법 내가 직면하고이 문제 .. 전화 할 때마다.

[self performSelector:@selector(reloaddatas) withObject:nil afterDelay:0.5f]; 
+0

도움을 주셔서 감사합니다. – Tommy