Self Sizing Cells使UITableView跳转 [英] Self Sizing Cells make UITableView jump

查看:94
本文介绍了Self Sizing Cells使UITableView跳转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,每个单元格都有一个图像和两个标签,正如你在第一张图片上看到的那样

I've got a UITableView, each cell has an image and two labels, as you can see on the first picture

所以我正在尝试使用自我调整大小的单元格,一切都是很棒,除了两件事:

So I am trying ti use self-sizing cells and everything is great, except 2 things:

1)第一和第二个单元格没有正确显示内容,但在我向下滚动然后返回它们之后一切正常。我试图在viewDidApper中使用[tableview reloadData],但它没有帮助。首先观看不合适的标签。您可以在此视频中观看 https://www.youtube.com/watch?v=I9DGBl1c5vg

1) First and Second cell don't show content properly, but after I scroll down and then return to them everything is ok. I tried to use [tableview reloadData] in viewDidApper, but it doesn't help. Watch the labels at first they don't fit. You can watch it on this video https://www.youtube.com/watch?v=I9DGBl1c5vg

查看第一个单元格上的标签。

Look at the labels on the first cell.

2)这是一个艰难的标签。我正在滚动表格,一切都很好,但是当我选择行时问题就出现了。它正在推动我进入细节视图,但是当我按下返回并返回到主视图时,tableview跳转,所以我回到不选择的行,如果我滚动表格它不会滚动平滑,但是跳跃。以下是两个视频的链接,第一个显示滚动顺畅 https://www.youtube。 com / watch?v = 9wAICcZwfO4 如果我没有进入详细视图,第二个显示跳跃问题 https://www.youtube.com/watch?v=fRcQ3Za1wDM

2) It's a tough one. I'm scrolling the table and everything is great, but the problem happens, when I select the row. It's pushing me to detail view, but when I press "back" and return to master view, the tableview jumps,so I'm coming back not to the selected row, also if I scroll the table it doesn't scroll smooth, but jumps. Here are the links for two videos, first one shows that scroll is smooth https://www.youtube.com/watch?v=9wAICcZwfO4 if i don't go to detail view, and the second shows the jumping problem https://www.youtube.com/watch?v=fRcQ3Za1wDM .

绝对确定与自定义单元格相关联,因为如果我不使用它,这个问题都不会发生。如果您需要一个显示正确功能的视频,请告诉我。

It's absolutely sure connected with self sizing cells,because if I don't use it,none of this problem happens. If you need a video that shows the right functionality, tell me.

推荐答案

好的,我解决了这两个问题。

Okay, I solved both of the problems.

问题1

我添加了这两行

[cell.contentView setNeedsLayout];
[cell.contentView layoutIfNeeded];


- (UITableViewCell *)tableView:(UITableView * )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 返回单元格之前

问题2

解决方案似乎非常简单。我只需要实现 viewWillDissapear 并重新加载数据,所以代码看起来像这样

The solution appeared to be very simple. I've just needed to implement viewWillDissapear and reload data in it, so the code looks like this

- (void)viewWillDisappear:(BOOL)animated;{
    [super viewWillDisappear:animated];
    [self.tableView reloadData];
}

对我来说解决方案很简单,如果它对某人不起作用,这里我发现了一些有用的链接。

1) UITableView布局混乱推送segue和返回。 (iOS 8,Xcode beta 5,Swift)

2) http://useyourloaf.com/blog/2014/08/07/self-sizing-table-view-cells.html

Solution for me was simple, if it doesn't work for someone, here I found some useful links.
1) UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift)
2) http://useyourloaf.com/blog/2014/08/07/self-sizing-table-view-cells.html

这篇关于Self Sizing Cells使UITableView跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆