自定义空TableView
嘿伙计们, 我遇到一个有趣的问题,我想要一个带有圆角和特定背景等的自定义表格视图...这工作正常,但一切都在 cellForRowAtIndexPath 中设置。这意味着如果我的表视图为空,则不会调用此方法,并且会显示这个丑陋的空白表视图。
我无法在 viewDidAppear 中进行修改,因为 tableView 是在其方法中声明的,例如前面提到的方法。有什么想法吗?
提前致谢!
Hey guys,
I'm having an interesting issue, where I want to have a customized table view with rounded corners and a specific background, etc... This works fine, but everything is being set up in cellForRowAtIndexPath. This means that if my table view is empty, this method doesn't get called, and I get this ugly, blank table view showing up.
I can't do the modifications in viewDidAppear, because the tableView gets declared in its methods such as the one mentioned earlier. Any ideas?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您只需要找到正确的位置来初始化表视图,并且由于您提到的原因,它不在 cellForRowAtIndexPath 中。假设您已在 xib 文件中创建了 UITableView,则可以在源代码中创建一个插座(见下文),并在 InterfaceBuilder 中在 xib 文件中创建控制器的实例,或使用现有实例(如 File's Owner) , 或许)。在 IB 中,通过按住 Control 键单击并拖动将该插座连接到表。当 xib 被加载时,UIKit 将填充指向你的表视图的指针,然后你可以在 viewDidLoad 期间疯狂地使用它。这能解决你的问题吗?
...
Sounds like you just need to find the right spot to initialize your table view, and it's not in cellForRowAtIndexPath, for the reasons you mentioned. Assuming you've created your UITableView in a xib file, you can create an outlet in your source code (see below), and in InterfaceBuilder either make an instance of your controller in the xib file, or use an existing instance (like File's Owner, maybe). In IB, connect that outlet to the table with control-click-drag. When the xib is loaded, UIKit will fill in the pointer to your table view, which you can then go nuts with during viewDidLoad. Does that solve your problem?
...