2012-10-17 22 views
6

enter image description hereenter image description here Tôi gặp sự cố lạ khi sử dụng GMGridView. Trên thực tế tôi đang sử dụng GMGridview để hiển thị các bảng nhà hàng. Nếu tôi chọn Table1 (có nghĩa là ô đầu tiên), nó sẽ thay đổi thành redColor (điều đó có nghĩa là nó chiếm bảng). Tôi đã làm điều này, Nhưng vấn đề của tôi là khi tôi chọn một ô 1 (redcolor), đó là màu đỏ được hiển thị trong tất cả các lớp bất cứ nơi nào tôi sử dụng GMGridview. Thats là hoàn toàn sai, mà không có bất kỳ lựa chọn trong lớp khác, nó được hiển thị như một lựa chọn.Lựa chọn GMGridView đang ghi đè

Trong những hình ảnh dưới đây, nếu tôi chọn 1, đó là thể hiện 7 cũng được lựa chọn .....

Và mã của tôi là

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index{ 



    CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication 
sharedApplication] statusBarOrientation]]; 


    GMGridViewCell *cell = [gridView dequeueReusableCell]; 


    int isOccupied = [[[self.arrayOfoccupiedTables objectAtIndex:index] objectForKey:@"TStatus"] intValue]; 


    if (!cell) 

    { 

     cell = [[[GMGridViewCell alloc] init] autorelease]; 


     UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; 

     cell.contentView = view; 

    } 


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


    UILabel *label = [[UILabel alloc] initWithFrame:cell.contentView.bounds]; 

    label.autoresizingMask = UIViewAutoresizingFlexibleWidth | 

UIViewAutoresizingFlexibleHeight; 

    label.textAlignment = UITextAlignmentCenter; 

    label.backgroundColor = [UIColor clearColor]; 

    label.font = [UIFont fontWithName:APPFONTLI size:22.0f]; 

    label.adjustsFontSizeToFitWidth = YES; 



    if (isOccupied == 100001) { 


     label.textColor = [UIColor whiteColor]; 

     label.highlightedTextColor = [UIColor blackColor]; 

     label.backgroundColor = [UIColor redColor];//redColor]; 

     //colorWithRed:43.0f/255.0f green:150.0f/255.0f blue:0.0f/255.0f alpha:1.0f];//GreenColor 

     label.text = [[self.filtredArray objectAtIndex:index] objectForKey:@"TableName"]; 


    }else if(isOccupied == 100002) { 



     label.textColor = [UIColor whiteColor]; 

     label.highlightedTextColor = [UIColor blackColor]; 

     label.backgroundColor = [UIColor colorWithRed:43.0f/255.0f green:150.0f/255.0f 
blue:0.0f/255.0f alpha:1.0f]; 

     //colorWithRed:215.0f/255.0f green:215.0f/255.0f blue:0.0f/255.0f alpha:1.0f];//GreenColor 

     label.text = [[self.filtredArray objectAtIndex:index] objectForKey:@"TableName"]; 

    } 

    else if(isOccupied == 100003) { 

     label.textColor = [UIColor blackColor]; 

     label.highlightedTextColor = [UIColor whiteColor]; 

     label.backgroundColor = [UIColor colorWithRed:215.0f/255.0f green:215.0f/255.0f blue:0.0f/255.0f alpha:1.0f];// Yellow Color 


     //colorWithRed:229.0f/255.0f green:229.0f/255.0f blue:229.0f/255.0f alpha:1.0f];//GrayColor 

     label.text = [[self.filtredArray objectAtIndex:index] objectForKey:@"TableName"]; 

    } 
    [cell.contentView addSubview:label]; 
    return cell; 
} 

- (void)GMGridView:(GMGridView *)gridView didTapOnItemAtIndex:(NSInteger)position 
{ 

    NSLog(@"Did tap at index %d", position); 

    [[SoundManager sharedSoundManager] playSound:SELECTED]; 

    //[self performSelector:@selector(registerTableToTheServer:) withObject:nil afterDelay:0.2]; 

    [self registerTableToTheServer:[[self filtredArray] objectAtIndex:position]]; 

    NSInteger tableId = [[[[self filtredArray] objectAtIndex:position] objectForKey:@"Table_id"] intValue]; 

    [self createPlistWithTableId:tableId]; 

    [_gmGridView reloadData]; 
} 

Và đó để tôi tải lại GridView trong viewWillAppear và viewDidLoad cũng vậy. Tôi đã không tìm thấy bất cứ điều gì hữu ích. Xin hãy giúp tôi ra ngoài.

Trả lời

6
- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index{ 
    
   CGSize size = [self GMGridView:gridView sizeForItemsInInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; 
    
   GMGridViewCell *cell = [gridView dequeueReusableCell]; 
   int isOccupied = [[[self.arrayOfoccupiedTables objectAtIndex:index] objectForKey:@"TStatus"] intValue]; 

   if (!cell)  { 
       cell = [[[GMGridViewCell alloc] init] autorelease]; 
            
       UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; 
       cell.contentView = view; 
   } 

    //TRY TO RELOAD THE MG_GRIDVIEW HERE 
} 
Các vấn đề liên quan