2013-10-30 9 views
2

내 프로젝트에 Collectionview가 있습니다 ... ipad 및 iphone ..에서 제대로 작동하지만 iPod ... IOS7 .. iPod의 버전이 아닌 사람이 문제가 무엇인지 말해 줄 수 있습니다 .. 내가 ... 내 코드가 문제iPod에서 Collectionview 문제

 _collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(-5, 0,  self.view.bounds.size.width, height) collectionViewLayout:layout]; 
    [_collectionView setDataSource:self]; 
    [_collectionView setDelegate:self]; 
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; 
    [_collectionView setBackgroundColor:[UIColor whiteColor]]; 
    [_collectionView setShowsHorizontalScrollIndicator:NO]; 
    [_collectionView setShowsVerticalScrollIndicator:NO]; 

    [self.view addSubview:_collectionView]; 


    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
    { 
    return arrayMonths.count; 
    } 

// The cell that is returned must be retrieved from a call to - dequeueReusableCellWithReuseIdentifier:forIndexPath: 
     - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
     { 
     UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; 
     for(UIView *subview in [cell subviews]) { 
     [subview removeFromSuperview]; 
     } 
     MonthView *month=[arrayMonths objectAtIndex:indexPath.row]; 
     if ([month.strMonthName isEqualToString:@"February"]) { 
     UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, -5, cell.frame.size.width, 40)]; 
     [label setText:[NSString stringWithFormat:@"%@ - %@",[[NSUserDefaults standardUserDefaults] valueForKey:@"KiCalName"],month.strYear]]; 
     label.textAlignment=NSTextAlignmentCenter; 
     [label setFont:[UIFont fontWithName:@"AmericanTypewriter-Bold" size:12.0]]; 
     [cell addSubview:label]; 
     [month setFrame:CGRectMake(0, 35, month.frame.size.width, month.frame.size.height)]; 
     }else if([month.strMonthName isEqualToString:@"January"] || [month.strMonthName isEqualToString:@"March"]){ 
     [month setFrame:CGRectMake(0, 35, month.frame.size.width, month.frame.size.height)]; 
     } 
     [cell addSubview:month]; 
     [hud hide:YES]; 
     return cell; 
     } 

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    MonthView *monthOld=[arrayMonths objectAtIndex:indexPath.row]; 
    CGRect rectNew=CGRectMake(monthOld.frame.origin.x, monthOld.frame.origin.y, monthOld.frame.size.width+40, monthOld.frame.size.height+40); 
    MonthView *month=[[MonthView alloc]initWithFrame:monthOld.frame andYear:monthOld.strYear andMonth:monthOld.strMonthName andNoOfDays:monthOld.noOfDays andArrayOffDays:monthOld.arrayOFF andArrayOnDays:monthOld.arrayONN]; 
    [month setBackgroundColor:[UIColor whiteColor]]; 
    UIView *view=[[UIView alloc]initWithFrame:rectNew]; 
    [view setBackgroundColor:[UIColor whiteColor]]; 
    [month setFrame:CGRectMake(20, 20, month.frame.size.width, month.frame.size.height)]; 
    [view addSubview:month]; 
    [[KGModal sharedInstance] setShowCloseButton:NO]; 
    [[KGModal sharedInstance] showWithContentView:view andAnimated:NO]; 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

    MonthView *month=[arrayMonths objectAtIndex:indexPath.row]; 
    NSLog(@"month name %@",month.strMonthName); 
    NSLog(@"month %@",month); 
    CGSize height; 
    height=CGSizeMake(105, 155); 
    if ([month.strMonthName isEqualToString:@"January"]) { 
     height=CGSizeMake(105, 190); 
     NSLog(@"called"); 
    }else if ([month.strMonthName isEqualToString:@"February"]){ 
     height=CGSizeMake(105, 190); 
     NSLog(@"called"); 
    }else if ([month.strMonthName isEqualToString:@"March"]){ 
     height=CGSizeMake(105, 190); 
     NSLog(@"called"); 
    }else{ 

    } 
    return height; 
} 


-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 1; 
} 

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 1; 
} 
+1

문제는 무엇입니까? iPod에서 실행할 때 어떤 문제가 발생합니까? –

+1

[cell.contentView addSubview :]; 셀 대신 addSubview –

+0

@JanakNirmal의 충돌이 발생합니다. –

답변

2

따르고 무엇을해야 당신은 셀을 dequeing된다는 것입니다,

UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; 

것은

은 전무 확인되지 않은 것입니다 .. !!!

사용하여 다음과 같은 조건,

if(cell==nil) 
{ 
//then alloc cell 
}