简体   繁体   English

自定义UITableViewCell,表格不会滚动到底部

[英]Custom UITableViewCell, table won't scroll to the bottom

I need to build an Airbnb-like table index for displaying real estate, for which I customised a prototype UITableViewCell with a height of 200 and two custom Labels (created using Storyboard) and a background image (added programmatically). 我需要建立一个类似于Airbnb的表格索引来显示房地产,为此我定制了一个原型UITableViewCell,其高度为200,并带有两个自定义标签(使用Storyboard创建)和一个背景图像(以编程方式添加)。 All this was laid over a TableViewController added using Storyboard. 所有这些都放置在使用Storyboard添加的TableViewController上。

The data is being fetched from a JSON file and contains 10 items. 正在从JSON文件中获取数据,其中包含10个项目。 But in the iPhone simulator (4-inch), 但是在iPhone模拟器(4英寸)中,

a) It won't scroll beyond the first three items. a)它不会滚动到前三个项目之外。 I can see only the top half of the third item. 我只能看到第三项的上半部分。 How do I make it scroll all the 10 items right to the bottom of the last item? 如何使所有10个项目向右滚动到最后一个项目的底部?

b) The table overlaps the top iPhone status bar (with battery and network status). b)该表与顶部iPhone状态栏重叠(带有电池和网络状态)。 The storyboard doesn't allow resizing of the TableView to exclude any padding from the top or bottom. 情节提要不允许调整TableView的大小以排除顶部或底部的任何填充。 How can I leave some padding from the top and the bottom of the table? 如何在表格的顶部和底部留下一些填充物?

Here is my cellForRowAtIndexPath from MainViewcontroller.m 这是我来自MainViewcontroller.m的 cellForRowAtIndexPath

- (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;
}

Just make sure , you added the below UITableView delegate method : 只需确保,您添加了以下UITableView委托方法:

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

For second case, you can try with this link . 对于第二种情况,您可以尝试使用此链接

I am not sure if this qualifies as a resolution to this question, but the app runs alright without any of the aforementioned problems on an actual iPhone. 我不确定这是否可以解决这个问题,但是该应用程序可以正常运行,而在实际的iPhone上没有任何上述问题。 For now I'm doing all the further building and testing on an iPhone. 目前,我正在iPhone上进行所有进一步的构建和测试。 I will come back to the simulator at the very end and hopefully it should be running there too. 我将在最后回到模拟器,并希望它也可以在那里运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM