iPhone + UITableView +行高

发布于 2024-08-09 18:18:16 字数 184 浏览 1 评论 0原文

我使用以下代码设置 UITableView 的行高,

[tableView setRowHeight: 100.00];

我在 UITableView 中使用单行作为分隔符。

即使设置了上面的高度,行的高度也不会改变。

I am setting the row height of my UITableView using following code

[tableView setRowHeight: 100.00];

I am using the single line as separator in the UITableView.

Eventhough setting the height above, height of row does not get change.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

恋竹姑娘 2024-08-16 18:18:16

您应该实现

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

委托方法。并在那里返回 100.0。

You should implement

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

delegate method. and return 100.0 there.

不必你懂 2024-08-16 18:18:16

如果所有行的高度相似,则应避免使用 heightForRowAtIndexPath 并使用 rowHeight 属性。根据文档:

使用 tableView:heightForRowAtIndexPath: 而不是 rowHeight 会对性能产生影响。每次显示表视图时,它都会在委托上为其每一行调用 tableView:heightForRowAtIndexPath: ,这可能会导致具有大量行(大约 1000 或更多)的表视图出现严重的性能问题。

例如,在 UITableViewController 子类中,可以在 viewDidAppear 方法中完成(UITableViewController 具有对 tableView 的引用):

self.tableView.rowHeight = 79.f;

You should avoid the heightForRowAtIndexPath if all your rows are of similar height and use the rowHeight property. According to the documentation:

There are performance implications to using tableView:heightForRowAtIndexPath: instead of rowHeight. Every time a table view is displayed, it calls tableView:heightForRowAtIndexPath: on the delegate for each of its rows, which can result in a significant performance problem with table views having a large number of rows (approximately 1000 or more).

In the UITableViewController subclass it could be done, for instance, in the viewDidAppear method (the UITableViewController has a reference to the tableView):

self.tableView.rowHeight = 79.f;
多像笑话 2024-08-16 18:18:16

当单元格首次显示时,行高被烘焙到单元格中。

设置数据源之前是否设置了UITableView#rowHeight?
如果没有,请这样做。
如果出于某种原因您不能,您的另一个选择是在设置行高后调用 UITableView#reloadData。

The row height is baked into the cells when they are first displayed.

Did you set UITableView#rowHeight before setting the data source?
If not, do so.
If for whatever reason you can't, your other option is to call UITableView#reloadData after setting the row height.

如梦亦如幻 2024-08-16 18:18:16

我确实喜欢这样做,这里的 tableobj 只是我的应用程序中的 UITableView 对象。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [tableObj setRowHeight:100.0f];
}

或者在numberOfRowsInSection:中处理它,例如:

- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section {
    [tableObj setRowHeight:100.0f];
    return [soandso count]; // soandso is my object
}

因为在设置数据源之前设置了rowHeight。它对我有用(对于相同的行高)。

I did like this, here tableobj is nothing but UITableView object in my application.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [tableObj setRowHeight:100.0f];
}

Or handle it in numberOfRowsInSection: like:

- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section {
    [tableObj setRowHeight:100.0f];
    return [soandso count]; // soandso is my object
}

Because set the rowHeight before setting the data source. It worked for me (for equal row heights).

誰ツ都不明白 2024-08-16 18:18:16

更好、更干净的解决方案是实现委托函数(如果你的 UITableView 有很多行,也许不是最好的解决方案......)。

另外,认为 UITableVieCell 是 UIView,所以你可以首先改变它们的高度...

代表在 iPhone 开发中非常强大,这里是 UITableViewDelage:

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

您还可以更改 indentForRow、displayCellForRow、heightForRow、编辑内容......

The better and cleaner solution is to implement the delegate function (Maybe not the best one if your UITableView has many rows ...).

Also, think that UITableVieCell are UIView so you could change their height firstly...

Delegates are very powerful in iPhone dev, here the UITableViewDelage:

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

You can also change the indentForRow, displayCellForRow, heightForRow,edit stuff .....

梓梦 2024-08-16 18:18:16

我认为 UITableView 中没有这样的方法...

相反,您可以使用属性 rowHeight...
尝试,
tableView.rowHeight =100;

I dont think there is such a method in UITableView...

Instead you can use the property rowHeight...
Try,
tableView.rowHeight =100;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文