iphone – GMGridView的选择是最重要的
发布时间:2020-12-14 19:45:55 所属栏目:百科 来源:网络整理
导读:我使用GMGridView时遇到了奇怪的问题.其实我用GMGridview来展示餐厅餐桌.如果我选择Table1(这意味着第一个单元格),它应该更改为redColor(这意味着它是被占用的表).我做了这个,但我的问题是当我选择一个单元格1(红色)时,所有类别中都会显示红色,而不管我使用G
我使用GMGridView时遇到了奇怪的问题.其实我用GMGridview来展示餐厅餐桌.如果我选择Table1(这意味着第一个单元格),它应该更改为redColor(这意味着它是被占用的表).我做了这个,但我的问题是当我选择一个单元格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,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,size.height)]; ? ? ? ?cell.contentView = view; ? ?} //TRY TO RELOAD THE MG_GRIDVIEW HERE } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |