gpt4 book ai didi

ios - UITableViewCell 不显示 subview

转载 作者:行者123 更新时间:2023-11-29 03:31:19 25 4
gpt4 key购买 nike

我正在使用以下代码来显示自定义 UITableViewCell。然而问题是它只显示 backImage 并且不显示任何其他标签或图像。

这是代码和 ss。

怎么了???

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImageView *maleIcon;
UIImageView *femaleIcon;
UIImageView *backImage;

UILabel *name;
UILabel *address;
UILabel *maleCount;
UILabel *femaleCount;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

VenueClass *venue = [self.venueArray objectAtIndex:[indexPath row]];

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyIdentifier"];
backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];

maleIcon = [[UIImageView alloc] initWithFrame:CGRectMake(234,143,25,25)];
femaleIcon = [[UIImageView alloc] initWithFrame:CGRectMake(234,173,25,25)];

maleIcon.image = [UIImage imageNamed:@"rectangle.png"];
femaleIcon.image = [UIImage imageNamed:@"rectangle.png"];

name = [[UILabel alloc] initWithFrame:CGRectMake(10,148,140,22)];
address = [[UILabel alloc] initWithFrame:CGRectMake(10,178,140,22)];
maleCount = [[UILabel alloc] initWithFrame:CGRectMake(266,145,48,22)];
femaleCount = [[UILabel alloc] initWithFrame:CGRectMake(266,175,48,22)];

name.font = [UIFont boldSystemFontOfSize:16];
address.font = [UIFont systemFontOfSize:14];
maleCount.font = [UIFont boldSystemFontOfSize:14];
femaleCount.font = [UIFont boldSystemFontOfSize:14];

name.backgroundColor = [UIColor clearColor];
address.backgroundColor = [UIColor clearColor];
maleCount.backgroundColor = [UIColor clearColor];
femaleCount.backgroundColor = [UIColor clearColor];

name.textColor = [UIColor whiteColor];
address.textColor = [UIColor whiteColor];
maleCount.textColor = [UIColor whiteColor];
femaleCount.textColor = [UIColor whiteColor];

[cell.contentView addSubview:backImage];
[cell.contentView addSubview:name];
[cell.contentView addSubview:address];
[cell.contentView addSubview:maleCount];
[cell.contentView addSubview:femaleCount];
[cell.contentView addSubview:femaleIcon];
[cell.contentView addSubview:maleIcon];

}

CLLocation *location = [[CLLocation alloc] initWithLatitude:[venue.latitude doubleValue] longitude:[venue.longitude doubleValue]];

AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
int distance = [location distanceFromLocation:appDelegate.myLocationCtrl.locationManager.location];
distance = distance / 1000;

[femaleCount setText:venue.femaleCount];
[maleCount setText:venue.maleCount];
[name setText:venue.name];
[address setText:[NSString stringWithFormat:@"%@/%d Km", venue.address, distance]];

cell.accessoryType = UITableViewCellAccessoryNone;
cell.backgroundColor = [UIColor clearColor];


NSString *path = [[NSString stringWithFormat:@"%@%@" ,IMAGE_URL, venue.imagePath ] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[backImage setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@""]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{
}];

return cell;
}

enter image description here

最佳答案

是的,您的背面图像太宽太高,您将其设置为 320x100 尝试 60x100

抱歉编辑:您的其他项目不在屏幕/单元格内,因为它们的 Y 坐标 >100。 Tr 减少 initWithFrame:CGRectMake(X, Y 必须小于单元格高度、宽度、高度)的第二个参数

关于ios - UITableViewCell 不显示 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19744247/

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