2012-06-20 1 views
0

Я добавил UIImageView в GMGridView, так как хочу отображать изображения в сетке. После добавления изображения в сетку все работает отлично. Я хочу показать другое изображение в первой строке & первый столбец. Поэтому я установил это изображение после компиляции с индексом. Но когда я прокручиваю вверх & вниз, он меняет изображение с первого столбца на 2-й или 3-й столбец. Также то же изображение отображается в 6-й или 7-й строке. Что в этом плохого? Вот мой кодИзображения в изображениях просматриваются после прокрутки GMGridView вверх и вниз в iphone

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index 
{ 
    CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; 

    GMGridViewCell *cell = [gridView dequeueReusableCell]; 

    UIImageView *imageView = nil; 
    if (!cell) 
    { 
     cell = [[GMGridViewCell alloc] init]; 
     cell.deleteButtonIcon = [UIImage imageNamed:@"close_x.png"]; 
     cell.deleteButtonOffset = CGPointMake(-15, -15); 

     imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)]; 

     cell.contentView = imageView; 

    } 

    NSLog(@"Project Index value:- %d",index); 
    if (index == 0) { 
     imageView.image = [UIImage imageNamed:@"add.png"]; 
    } 
    else{ 
     imageView.image = [UIImage imageNamed:@"face.png"]; 
    } 

    [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];  
    return cell; 
} 

сделать Также мне нужно [[cell.contentView подвиды] makeObjectsPerformSelector: @selector (removeFromSuperview)]; ? Может ли кто-нибудь мне помочь? Благодаря

ответ

1

Попробуйте использовать код

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index { 
    CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; 
    GMGridViewCell *cell = [gridView dequeueReusableCell]; 

UIImageView *imageView = nil; 
if (!cell) 
{ 
    cell = [[GMGridViewCell alloc] init]; 
    cell.deleteButtonIcon = [UIImage imageNamed:@"close_x.png"]; 
    cell.deleteButtonOffset = CGPointMake(-15, -15); 

    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)]; 
    NSLog(@"Project Index value:- %d",index); 
    if (index == 0) { 
     imageView.image = [UIImage imageNamed:@"add.png"]; 
    } 
    else{ 
     imageView.image = [UIImage imageNamed:@"face.png"]; 
    } 
     [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];  
    cell.contentView = imageView; 

} 
return cell; 

}

Я думаю, что проблема может быть, вы удаляете ячейку с помощью makeObjectsPerformSelector, а затем он никогда не будет добавлен снова после удаления с контроля может не входит в состояние if (!cell) {} в связи с наличием экземпляра cell. Надеюсь, это вам поможет.

+0

Это сработало для меня, когда ничего больше не было ... спасибо! – codeburn

Смежные вопросы