处理空的UITableView。打印友好的信息 [英] Handling an empty UITableView. Print a friendly message

查看:96
本文介绍了处理空的UITableView。打印友好的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,在某些情况下,空是合法的。因此,我不想显示应用程序的
背景图片,而是希望在屏幕上打印友好消息,例如:

I have a UITableView that in some cases it is legal to be empty. So instead of showing the background image of the app, I would prefer to print a friendly message in the screen, such as:


此列表现在为空

This list is now empty

最简单的方法是什么?

What is the simplest way to do it?

推荐答案

UITableView的backgroundView属性是你的朋友。

UITableView's backgroundView property is your friend.

In viewDidLoad 或者你 reloadData 的任何地方你应该确定你的表是否为空并用UIView更新UITableView的backgroundView属性包含UILabel或只是将其设置为nil。就是这样。

In viewDidLoad or anywhere that you reloadData you should determine if there your table is empty or not and update the UITableView's backgroundView property with a UIView containing a UILabel or just set it to nil. That's it.

当然可以让UITableView的数据源执行双重任务并返回一个特殊的list is empty单元格,它让我感觉像是一个kludge。突然 numberOfRowsInSection:(NSInteger)部分必须计算未被询问的其他部分的行数,以确保它们也是空的。您还需要创建一个具有空消息的特殊单元格。另外,请不要忘记您可能需要更改单元格的高度以容纳空消息。这一切都是可行的,但似乎是在创可贴之上的创可贴。

It is of course possible to make UITableView's data source do double duty and return a special "list is empty" cell, it strikes me as a kludge. Suddenly numberOfRowsInSection:(NSInteger)section has to compute the number of rows of other sections it wasn't asked about to make sure they are empty too. You also need to make a special cell that has the empty message. Also don't forget that you need to probably change the height of your cell to accommodate the empty message. This is all doable but it seems like band-aid on top of band-aid.

这篇关于处理空的UITableView。打印友好的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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