当insertRowAtIndexPaths时,单元格大小变得紧凑 [英] When insertRowAtIndexPaths, the cells size get compact

查看:120
本文介绍了当insertRowAtIndexPaths时,单元格大小变得紧凑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的`UITableView`。我想要做的是在用户选择按钮时添加一行。



这是我的代码:



  - (IBAction)addRow:( id )sender 
{
NSInteger row = [ self .rowArray count] - 1 ;
[ self .rowArray insertObject: @ cellIDRowSeven atIndex:row];

NSIndexPath * indexPath = [NSIndexPath indexPathForRow:row inSection: 0 ];
[ self .myTableView insertRowsAtIndexPaths:@ [indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}





一切都运作良好,除了事实,当添加一行时,细胞尽可能小。



例如。我有一个带按钮的单元格。按钮比应有的大。这意味着如果按钮的文本大小为14,那么按钮应该是最小的尺寸,比方说,30。(我编了那个数字。)然后我将大小设置为35.所以当这个行被添加时,它就是使按钮大小为30.



基本上,它使所有单元格尽可能紧凑。





----------





奇怪的是,当我只需要



[self.myTableView reloadData]



它完美无瑕,但我没有那个动画。

解决方案

那是Autolayout。您必须在接口构建器或代码中将单元格的高度设置为固定值。



稳定这篇有趣的文章动态表视图单元格高度和自动布局。充其量:阅读整个网站并观看视频。花钱会节省你(和我)的时间。 ; - )

I have a custom `UITableView`. What I'm trying to do is add a row when the user selects a button.

Here is my code:

- (IBAction)addRow:(id)sender
{
    NSInteger row = [self.rowArray count] - 1;
    [self.rowArray insertObject:@"cellIDRowSeven" atIndex:row];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
    [self.myTableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}



Everything works well, besides for the fact, that when a row gets added, the cells get as small as possible.

For example. I have a cell with buttons in it. The button is bigger than it should be. Meaning that if the button has text with the size of 14, the smallest size the button should be is, say, 30. (I made up that number.) And I made the size to 35. So when the row gets added, it makes the buttons size to 30.

Basically, it makes all the cells as compact as possible.


----------


The weird thing is, when I just do

[self.myTableView reloadData]

It works flawlessly, but I don't have that animation.

解决方案

That is Autolayout. You must set the heigth of the cell in the Interface builder or code as fixed value.

Stady this interesting article Dynamic Table View Cell Height and Auto Layout. At best: read the whole website and watch the videos. The money spend will save your (and my) time. ;-)


这篇关于当insertRowAtIndexPaths时,单元格大小变得紧凑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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