如果我的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];
}
关于iphone - 注册tableView使用willDisplayCell完成加载-不适用于0个结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15218245/