如果UITableView为空,则显示UIAlertView

时间:2011-09-06 11:00:29

标签: iphone xcode count tableview

我有RSS,UITableView从中加载数据,如果UITableView为空,我怎么能显示UIAlertView,而不是数组的数量,因为每次刷新时数组都不同,是否有某种功能它会在完成绘图后检查UITableView是否为空?

2 个答案:

答案 0 :(得分:4)

您可以查询UITableView本身。因此,假设您有一个部分,您可以执行以下操作...

// Reload the tableview
[tableView reloadData];
// Test the number of rows in the first section
if ([tableView numberofRowsInSection:0] == 0) {
    // Display UIAlertView here
}

EDIT;根据以下评论......

在头文件(.h)中,iVar声明......

int feedCount;
int feedsParsed;

在您的实施中......

- (void)refresh {
    feedCount = 0;
    feedsParsed = 0;

    [feedParser stopParsing];
    self.title = @"Refreshing...";
    [parsedItems removeAllObjects];
    for (NSString *imePredmeta in [Data variables].mojiPredmeti) {
        ... // I've removed these lines for brevity but they are still required
        [feedParser parse];
        feedCount += 1;
    }
    // Delete everything else after this line
}

- (void)feedParserDidFinish:(MWFeedParser *)parser {
    feedsParsed += 1;
    if (feedsParsed == feedCount) {
        [self.tableView reloadData];
        if ([self.tableView numberofRowsInSection:0] == 0) {
            // Fade out tableview and display alert here as we now know for
            // sure that there are no more feeds to parse and we definitely
            // have nothing to display
        }
    }
 } 

答案 1 :(得分:0)

您需要循环数组并检查以确定是否没有结果。 如果您想要更明确的答案,请发布您现有的tableview代码。

编辑:上面的micpringle答案更好。