【问题标题】:Custom UITableViewCell, table won't scroll to the bottom自定义 UITableViewCell,表格不会滚动到底部
【发布时间】: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


【解决方案1】:

请确保,您添加了以下 UITableView 委托方法:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}

对于第二种情况,你可以试试这个link。

【讨论】:

  • 谢谢,这显示了整个表格单元格。但我仍然无法滚动超过 3 个项目。还有什么我做错了吗? (请参阅我添加到原始帖子中的代码)。
  • @bombaypundit 然后尝试增加 TableView 的大小,即增加到 (320,420);,可能会成功。您是否看到完整的 tableView 或者您可以发布应用截图。
【解决方案2】:

我不确定这是否可以作为该问题的解决方案,但该应用程序运行良好,在实际 iPhone 上没有任何上述问题。现在,我正在 iPhone 上进行所有进一步的构建和测试。我会在最后回到模拟器,希望它也应该在那里运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-14
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多