gpt4 book ai didi

iOS tableview customcell - 屏幕外单元格上的控件有时不可见

转载 作者:行者123 更新时间:2023-11-29 01:47:22 24 4
gpt4 key购买 nike

我在包含 5 个单元格的 TableView 中遇到了一个奇怪的错误。由于单元格高度较大,第五个单元格最初不在屏幕上,用户需要向下滚动才能看到它。这些单元格显示一个下载按钮、一个进度指示器,如果下载完成,则显示一个查看按钮而不是下载和进度。

前 4 个单元格显示正确。然而,第五个单元格有时会丢失下载按钮,但有时它会在每次重新启动应用程序时以大约 %50 的几率正确显示。源数据在任何时候都不会更改。

我已经使用断点来查看向下滚动时会发生什么,但我无法发现任何异常,并且在出现单元格时正确提供了数据。

谁能告诉我应该关注哪里?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
static NSString *MyIdentifier = @"cell1";
NSDictionary *categoryDictionary= [[appdelegate categoriesArray] objectAtIndex:indexPath.row];
categoryTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
rect=cell.labelProgressView.frame;
cell.backgroundColor = [UIColor PGColorBackground];
cell.buttonView.hidden=YES;
//Set background colors and icons
switch ([[categoryDictionary valueForKey:@"categoryID"] intValue])
{
case 1:
[cell.buttonView setBackgroundColor: [UIColor PGColorAttractions]] ;
[cell.labelProgressView setBackgroundColor: [UIColor PGColorAttractions]] ;
[cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"attraction-bg"]];
cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"attractionWhite"];
break;
case 2:
[cell.buttonView setBackgroundColor: [UIColor PGColorRestaurants]];
[cell.labelProgressView setBackgroundColor: [UIColor PGColorRestaurants]];
[cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"restaurant-bg"]];
cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"restaurantWhite"];
break;
case 3:
[cell.buttonView setBackgroundColor: [UIColor PGColorShopping]];
[cell.labelProgressView setBackgroundColor:[UIColor PGColorShopping]];
[cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"shopping-bg"]];
cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"shoppingWhite"];
break;
case 4:
[cell.buttonView setBackgroundColor: [UIColor PGColorAccomodations]];
[cell.labelProgressView setBackgroundColor:[UIColor PGColorAccomodations]];
[cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"accomodation-bg"]];
cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"accomodationWhite"];
break;

case 5:
[cell.buttonView setBackgroundColor: [UIColor PGColorArtGalleries]];
[cell.labelProgressView setBackgroundColor:[UIColor PGColorArtGalleries]];
[cell.ivCategoryBannerImage setImage: [UIImage imageNamed:@"artGallery-bg"]];
cell.ivcategoryLogoImage.image =[UIImage imageNamed:@"artGalleryWhite"];
break;

default:
break;
}

//DOWNLOAD Button
[cell.buttonViewDownload setBackgroundColor:[UIColor clearColor]];
cell.buttonViewDownload.layer.borderColor=[UIColor whiteColor].CGColor;
cell.buttonViewDownload.layer.borderWidth=1.0f;
[cell.buttonViewDownload.titleLabel setFont:[UIFont fontWithName:@"OpenSans-Bold" size:10]];
[cell.buttonViewDownload setTag:[[categoryDictionary valueForKey:@"categoryID"] intValue]];

//VIEW Button
cell.buttonView.layer.borderColor=[UIColor whiteColor].CGColor;
cell.buttonView.layer.borderWidth=1.0f;
[cell.buttonView.titleLabel setFont:[UIFont fontWithName:@"OpenSans-Bold" size:10]];
[cell.buttonView setTag:[[categoryDictionary valueForKey:@"categoryID"] intValue]];
[cell.buttonView addTarget:self action:@selector(viewbuttonClicked:) forControlEvents:UIControlEventTouchUpInside];

//CATEGORY label

NSString *categoryName =[[NSString stringWithFormat:@"%@",[categoryDictionary valueForKey:@"categoryNameen"]] uppercaseString];

NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:categoryName];

[attributedString addAttribute:NSKernAttributeName
value:[NSNumber numberWithFloat:8.0]
range:NSMakeRange(0, [categoryName length])];

[attributedString addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"OpenSans-Bold" size:19]
range:NSMakeRange(0, [categoryName length])];


[cell.labelCategory setAttributedText:attributedString];

cell.selectionStyle=UITableViewCellAccessoryNone;
//Set State
cell.ivCategoryBannerImage.alpha =0.1f;

BOOL isAvailable = [[categoryDictionary valueForKey:@"isAvailable"] boolValue];
BOOL userTappedDownload = [[categoryDictionary valueForKey:@"userTappedDownload"] boolValue];

NSLog(@"isAvailable: %d", isAvailable);
NSLog(@"userTappedDownload: %d", isAvailable);

if (isAvailable && userTappedDownload)
{
cell.buttonView.hidden=NO;
[cell.buttonView setTitle:@"VIEW" forState:UIControlStateNormal];
cell.buttonViewDownload.hidden=YES;
cell.ivCategoryBannerImage.alpha =1.0f;
rect.size.width=208.0f;
}
else if(!isAvailable && !userTappedDownload)
{
rect.size.width=0.1f;
[cell.buttonViewDownload setTitle:[NSString stringWithFormat:@"DOWNLOAD (%@ KB)",[categoryDictionary valueForKey:@"totalImagesSize"]] forState:0];
}
else if(!isAvailable && userTappedDownload)
{
rect.size.width=[[categoryDictionary valueForKey:@"totalImagesAvailable"] intValue];
[cell.buttonViewDownload setTitle:@"DOWNLOADING CONTENT" forState:UIControlStateNormal];
cell.buttonViewDownload.userInteractionEnabled = NO;
}
return cell;
}

最佳答案

第五个单元格可能正在重复使用之前设置了 cell.buttonViewDownload.hidden=YES; 的单元格之一。

尝试将 cell.buttonViewDownload.hidden=NO; 添加到应显示下载按钮的分支。

关于iOS tableview customcell - 屏幕外单元格上的控件有时不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747260/

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