gpt4 book ai didi

ios - 如何防止 UITableViewCell 的背景 View 在点击时被清除?

转载 作者:行者123 更新时间:2023-11-29 01:16:52 25 4
gpt4 key购买 nike

出于某种奇怪的原因,当用户点击 UITableView 中的单元格时,cell.backgroundView 图像会被清除,并且仅显示我设置为占位符的灰色背景。据我所知,didSelectRowAtIndexPath 中没有任何内容会告诉 backgroundView 重置。为什么会发生这种情况?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Cell Identifier
static NSString *SecondCellIdentifier = @"SecondMatchCenterCell";
MatchCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:SecondCellIdentifier];
if (!cell) {
// if no cell could be dequeued create a new one
cell = [[MatchCenterCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SecondCellIdentifier];
}

// Separator style
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

// title of the item
_searchTerm = [[[[_matchCenterData objectAtIndex:indexPath.section] objectForKey:@"Top 3"] objectAtIndex:0]objectForKey:@"Search Term"];
cell.textLabel.text = _searchTerm;

// Display placeholder while downloading images using background thread
cell.backgroundColor = [UIColor lightGrayColor];
cell.imageView.image = nil;

// asynchronously download image
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:_matchCenterData[indexPath.section][@"Top 3"][indexPath.row+1][@"Image URL"]]];

dispatch_async(dispatch_get_main_queue(), ^{
// Setup imageView
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageWithData:imageData]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;

// create effect
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

// add effect to an effect view
UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:blur];
effectView.frame = self.view.frame;

// add the effect view to the image view
[imageView addSubview:effectView];
cell.backgroundView = imageView;
});

});

return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_searchTerm = [[[[_matchCenterData objectAtIndex:indexPath.section] objectForKey:@"Top 3"] objectAtIndex:0]objectForKey:@"Search Term"];
NSLog(@"The search term that was just selected: %@", _searchTerm);
//Set _sectionSelected variable to the section index
self.sectionSelected = indexPath.section;
self.sectionSelectedSearchTerm = _searchTerm;

[self performSegueWithIdentifier:@"MCExpandedSegue" sender:self];
}

最佳答案

In cellForRowAtIndexPath write this line.
This may help u

cell.selectionStyle = UITableViewCellSelectionStyleNone;

关于ios - 如何防止 UITableViewCell 的背景 View 在点击时被清除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35073307/

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