iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – GMGridView的选择是最重要的大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我使用GMGridView时遇到了奇怪的问题.其实我用GMGridview来展示餐厅餐桌.如果我选择Table1(这意味着第一个单元格),它应该更改为redColor(这意味着它是被占用的表).我做了这个,但我的问题是当我选择一个单元格1(红色)时,所有类别中都会显示红色,而不管我使用GMGridview.这是完全错误的,没有在另一个类中进行任何选择,它显示为选定的一个. 在下面的图像中,如果我选
@H_944_18@ 我使用GMGridView时遇到了奇怪的问题.其实我用GMGridview来展示餐厅餐桌.如果我选择Table1(这意味着第一个单元格),它应该更改为redColor(这意味着它是被占用的表).我做了这个,但我的问题是当我选择一个单元格1(红色)时,所有类别中都会显示红色,而不管我使用GMGridview.这是完全错误的,没有在另一个类中进行任何选择,它显示为选定的一个.

在下面的图像中,如果我选择了1,它显示7也被选中…..@H_944_21@

我的代码是@H_944_21@

- (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,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];
}

那我要在viewWillAppear和viewDidLoad中重新加载gridview.我没有找到任何有用的东西.请帮帮我们.@H_944_21@

解决方法

- (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,size.height)];
        cell.contentView = view;
    }

   //TRY TO RELOAD THE MG_GRIDVIEW HERE
}

大佬总结

以上是大佬教程为你收集整理的iphone – GMGridView的选择是最重要的全部内容,希望文章能够帮你解决iphone – GMGridView的选择是最重要的所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。