簡體   English   中英

使用willDisplayCell注冊tableView完成加載 - 不能使用0結果

[英]Register tableView finished loading with willDisplayCell - doesn't work with 0 results

如果我的tableView沒有顯示任何內容,我需要提醒用戶有0個結果。 我在我的willDisplayCell方法中執行此操作,但如果有0結果則不會注冊。 有誰知道如何修改這個? 謝謝!

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

if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] 
lastObject]).row) {

    if ([self.listItems count] == 0) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results" message:@"No 
        results found" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
}
}

您可以在viewWillAppear方法中顯示警報,因為您的行數為0,因此您的willDisplayCell方法未被調用,如果仔細查看willDisplayCell方法,您將找到一個參數forRowAtIndexPath ,這就是為什么它不被調用,因為行數為零。

-(void)viewWillAppear:(BOOL)animated
 {

    if ([self.listItems count] == 0)
    {
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results" message:@"No 
       results found" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
       [alert show];
    }
    else
    {
       [tableView reloadData];
    }
     [super viewWillAppear:animated];
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM