gpt4 book ai didi

iphone - UITableViewCells出现在backgroundView后面

转载 作者:行者123 更新时间:2023-12-03 20:01:29 28 4
gpt4 key购买 nike

我在将 UITableView 的背景设置为 UIImageView 时遇到问题(请参阅下文了解我这样做的原因),设置 View 后,它工作正常,并与 UITableView 一起滚动,但它隐藏了 UITableView 的元素表格 View 。

我需要一个 UIImageView 作为 UITableView 的背景。我知道以前已经回答过这个问题,但答案是使用:

[UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]];

或者类似的东西(我需要使用):

UIImageView *background = [MainWindow generateBackgroundWithFrame:tableView.bounds];
[tableView addSubview:background];
[tableView sendSubviewToBack:background];

我需要使用后者的原因是因为我的generateBackgroundWithFrame方法,它需要一个大图像,并在该图像周围绘制指定尺寸的边框,并剪辑图像的其余部分:

+ (UIImageView *) generateBackgroundWithFrame: (CGRect)frame {
UIImageView *background = [[[UIImageView alloc] initWithFrame:frame] autorelease];
background.image = [UIImage imageNamed:@"globalBackground.png"];
[background.layer setMasksToBounds:YES];
[background.layer setCornerRadius:10.0];
[background.layer setBorderColor:[[UIColor grayColor] CGColor]];
[background.layer setBorderWidth:3.0];

return background;
}

请注意:我知道这可能会对性能产生不良影响,但我没有资源来为应用程序中的每个潜在屏幕制作这些图像。请不要用无意识的“你不应该这样做”的回答来回答这个问题。我知道这可能是错误的做法。

如何显示我的 UITableView 控件元素?我的代表是否做错了什么?这是一个简化版本:

- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectMake(20, 20, 261, 45)
reuseIdentifier:CellIdentifier] autorelease];

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

UIImage *rowBackground;
NSString *imageName = @"standAloneTVButton.png";
rowBackground = [UIImage imageNamed:imageName];

UITextView *textView =
[[UITextView alloc] initWithFrame:CGRectMake(0, 5, 300, 200)];

textView.backgroundColor = [UIColor clearColor];
textView.textColor = [UIColor blackColor];
textView.font = [UIFont fontWithName:@"Helvetica" size:18.0f];

Purchase *purchase =
[[PurchaseModel productsPurchased] objectAtIndex:indexPath.row];

textView.text = [purchase Title];

selectedTextView.text = textView.text;


UIImageView *normalBackground =
[[[UIImageView alloc] init] autorelease];

normalBackground.image = rowBackground;

[normalBackground insertSubview:textView atIndex:0];

cell.backgroundView = normalBackground;
[textView release];
}

return cell;
}

最佳答案

所以到目前为止这个问题的答案是向背景 View 添加一个标签,然后执行以下操作:

- (void)tableView: (UITableView *)tableView willDisplayCell: (UITableViewCell *)cell forRowAtIndexPath: (NSIndexPath *)path {
[tableView sendSubviewToBack:[tableView viewWithTag:BACKGROUNDVIEW_TAG]];
}

我不太喜欢这个,因为我对每个单元格都这样做,但我似乎找不到 allCellsDidLoadForTableView: (UITableView *)tableView某种方法。

关于iphone - UITableViewCells出现在backgroundView后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2664596/

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