gpt4 book ai didi

iphone - GMGridView 选择被覆盖

转载 作者:可可西里 更新时间:2023-11-01 03:52:36 28 4
gpt4 key购买 nike

enter image description here enter image description here我在使用 GMGridView 时遇到了奇怪的问题。实际上,我正在使用 GMGridview 来显示餐厅餐 table 。如果我选择了 Table1(即第一个单元格),它应该变为红色(这意味着它已被占用)。我这样做了,但我的问题是当我选择一个单元格 1(红色)时,无论我在哪里使用 GMGridview,红色都显示在所有类中。那是完全错误的,在另一个类中没有任何选择,它显示为选中的。

在下面的图片中,如果我选择了 1,则显示还选择了 7.....

我的代码是

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

我也在 viewWillAppear 和 viewDidLoad 中重新加载 gridview。我没有找到任何有用的东西。请帮帮我。

最佳答案

- (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
}

关于iphone - GMGridView 选择被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12927963/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com