如果 tableView 没有结果则显示警报 [英] Display Alert if tableView has no Results

查看:27
本文介绍了如果 tableView 没有结果则显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前以为我可以用一个简单的数组计数来回答这个问题(我的错误).我正在尝试向用户 id 显示警告,因为 tableView 没有结果.我不能简单地将计数放在 viewDidAppear 方法中,因为填充 JSON 和 tableView 的 Web 查询需要几秒钟才能填充.我不能简单地把它放在:

I previously thought I could answer this question with a simple array count (my mistake). I am trying to display an alert to the user id a tableView has no results. I cannot simply place the count in the viewDidAppear method because the web query that populates the JSON and tableView takes a few seconds to populate. I cannot simply place this in:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath {

    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] 
    lastObject]).row){
    //loading complete
    }
}

因为如果没有结果,则此方法中不会调用任何内容.有没有人对此有任何建议 - 搜索了 4 个多小时,几乎把我所有的头发都拔掉了.

Because nothing gets called in this method if there are no results. Does anyone have any recommendations for this - been searching for over 4 hours and have pulled nearly all my hair out.

如果这个问题更适合 SO,请随时取消投票 - 这个问题大量的投票让我失去了提问的能力......

Please feel free to un-downvote this questions if it has been made more suitable for SO - this questions massive downvotes have cost me my ability to ask questions...

推荐答案

您无法在 viewDidAppear 中检查行数,因为使用异步 NSURLConnection 获取 JSON 数据填充表格视图.

You cannot check the row count in viewDidAppear because an asynchronous NSURLConnection is used to fetch the JSON data that populates the table view.

正确的方法是在使用来自 URL 请求的响应更新数据源后,在 connectionDidFinishLoading 中调用 reloadData.那时你就知道行数是否为零,并且不需要等待表视图更新完成.

The correct way is to call reloadData in connectionDidFinishLoading, after you have updated your data source with the response from the URL request. At that point you know if the number of rows is zero or not, and there is no need to wait for the table view update to complete.

这篇关于如果 tableView 没有结果则显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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