Creating a UITableView with Taller Cells on the iPhone

我只是一个虾纸丫 提交于 2020-01-02 05:29:13

问题


How can I go about creating a UITableView with taller cells? Basically, I want to create a full screen table with only four cells, but they should take up the entire screen (1/4 each).

Assuming this is possible using a UITableView, can it be done both in code and in Interface Builder? And also, can each cell have its own height?

--Tim


回答1:


For best performance, if all your rows are the same height, use the rowHeight property. It's accessible from both code and Interface Builder.

If you want to customise individual row heights, then you need to implement the - tableView:heightForRowAtIndexPath: delegate method. It's a little slower performing, but more flexible.




回答2:


Just use the -tableView:heightForRowAtIndexPath: method from the UITableViewDelegate protocol to customize the height of each cell. Something like this works just fine:

- (CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70.0f;
}

Hope that helps.



来源:https://stackoverflow.com/questions/410224/creating-a-uitableview-with-taller-cells-on-the-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!