使用UITableViewController与小型表? [英] Using a UITableViewController with a small-sized table?

查看:103
本文介绍了使用UITableViewController与小型表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用UITableViewController时,initWithStyle:方法根据文档自动创建底层的UITableView - 正确的尺寸。

When using a UITableViewController, the initWithStyle: method automatically creates the underlying UITableView with - according to the documentation - "the correct dimensions".

我的问题是这些正确的尺寸似乎320x460(iPhone的屏幕尺寸),但我推这个TableView /控制器对成一个UINavigationController本身包含在一个UIView,它本身是屏幕的高度的一半。

My problem is that these "correct dimensions" seem 320x460 (the iPhone's screen size), but I'm pushing this TableView/Controller pair into a UINavigationController which is itself contained in a UIView, which itself is about half the height of the screen.

没有框架或边界争用我可以想出似乎正确地重置了表的大小,因此它的太长,意味着有一组行从底部推出

No frame or bounds wrangling I can come up with seems to correctly reset the table's size, and as such it's "too long", meaning there are a collection of rows that are pushed off the bottom of the screen and are not visible nor reachable by scrolling.

所以我的问题是:什么是正确的方式告诉UITableViewController调整其组件UITableView的大小指定的矩形?

So my question comes down to: what is the proper way to tell a UITableViewController to resize its component UITableView to a specified rectangle?

谢谢!

更新建议这里没有效果,但我发现一个有趣的事情:如果我完全避开UINavigationController(我还不愿意做生产,但作为一个实验),并添加表视图作为一个直接我提到的封闭视图的子视图,符合的框架大小非常时候我重新引入UINavigationController到混合中,无论它是作为子视图添加到表视图之前还是之后,无论是在表视图之前还是之后的alloc / init作为一个子视图,结果与之前一样。

Update I've tried all the techniques suggested here to no avail, but I did find one interesting thing: if I eschew the UINavigationController altogether (which I'm not yet willing to do for production, but as an experiment), and add the table view as a direct subview of the enclosing view I mentioned, the frame size given is respected. The very moment I re-introduce the UINavigationController into the mix, no matter if it is added as a subview before or after the table view, and no matter if alloc/init it before or after the table view is added as a subview, the result is the same as it was before.

我开始怀疑UINavigationController不是一个团队球员...

I'm beginning to suspect UINavigationController isn't much of a team player...

更新2 在屏幕上的表视图之后检查框架大小的建议是一个好结果:导航控制器实际上在调整大小它在加载和显示之间的一些时间。我的解决方案,最好的hacky,一直缓存框架给予加载和重置它,如果改变在tableView:cellForRowAtIndexPath:开始。你为什么要问?因为它是我发现工作的一个地方,这就是为什么!

Update 2 The suggestion to check frame size after the table view on screen was a good one: turns out that the navigation controller is in fact resizing it some time in between load and display. My solution, hacky at best, has been to cache the frame given on load and to reset it if changed at the beginning of tableView:cellForRowAtIndexPath:. Why there you ask? Because it's the one place I found that worked, that's why!

我不认为这是一个解决方案,因为它显然不当,但为了任何人阅读的好处,它似乎工作。

I don't consider this a solution as it's obviously improper, but for the benefit of anyone else reading, it does seem to work.

推荐答案

为什么不只是使用一个普通的UIViewController和手动创建表?

Why not just use a regular UIViewController and create the table manually?

这篇关于使用UITableViewController与小型表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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