简体   繁体   中英

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). All this was laid over a TableViewController added using Storyboard.

The data is being fetched from a JSON file and contains 10 items. But in the iPhone simulator (4-inch),

a) It won't scroll beyond the first three items. 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?

b) The table overlaps the top iPhone status bar (with battery and network status). The storyboard doesn't allow resizing of the TableView to exclude any padding from the top or bottom. How can I leave some padding from the top and the bottom of the table?

Here is my cellForRowAtIndexPath from 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;
}

Just make sure , you added the below UITableView delegate method :

- (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. For now I'm doing all the further building and testing on an iPhone. I will come back to the simulator at the very end and hopefully it should be running there too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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