【发布时间】:2023-03-03 04:35:01
【问题描述】:
我需要构建一个类似于 Airbnb 的表格索引来显示房地产,为此我定制了一个高度为 200 的原型 UITableViewCell 和两个自定义标签(使用 Storyboard 创建)和一个背景图像(以编程方式添加)。所有这些都放在使用 Storyboard 添加的 TableViewController 上。
数据是从一个 JSON 文件中提取的,包含 10 个项目。但是在iPhone模拟器(4寸)中,
a) 它不会滚动到前三个项目之外。我只能看到第三项的上半部分。如何让它将所有 10 个项目滚动到最后一个项目的底部?
b) 表格与顶部的 iPhone 状态栏重叠(包括电池和网络状态)。故事板不允许调整 TableView 的大小以排除顶部或底部的任何填充。如何在表格的顶部和底部留下一些填充?
这是我的 cellForRowAtIndexPath 来自 MainViewcontroller.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
RealEstateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
RealEstate *estates = [self.allEstate objectAtIndex:indexPath.row];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];
cell.titleLabel.text=estates.title;
cell.infoLabel.text=[NSString stringWithFormat:@"%@ | %@",[properties formattedDate], [estates organiser]];
NSURL *url = [NSURL URLWithString:estates.photoURL];
NSData *data =[NSData dataWithContentsOfURL:url];
UIImage *img=[UIImage imageWithData:data];
[cell.backgroundView setContentMode:UIViewContentModeScaleAspectFill];
cell.backgroundView = [[UIImageView alloc] initWithImage:img];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:img];
return cell;
}
【问题讨论】:
-
发布您的相关代码
-
@iDev - 添加了代码。
-
我知道这可能为时已晚,但出于我自己的好奇心,你是如何在你的 tableview 上滚动的,你是在 ios 模拟器上使用两个手指手势吗?
标签: ios iphone uitableview