-1

如果 tableView 中没有结果,我想显示警报。我使用下面的 numberOfRowsInSection,但没有显示警报。我还删除了检查计数的 if 语句,以防万一出现问题。有谁知道为什么不显示警报?任何帮助都会很棒。谢谢!

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




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

if (tableView == self.searchDisplayController.searchResultsTableView) {
    return [self.filteredListItems count];
}

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

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

    }    
    }
}
4

3 回答 3

2

它不显示,因为您在显示警报之前返回:

else {
    return [self.listItems count]; 
...
于 2013-03-05T06:33:03.830 回答
0

看到问题是这条线return [self.listItems count]; 原因是你的执行没有超出这个范围。将其更改为:

else 
{
    if ([self.listItems count] == 0) 
    {
         //CALL ALERT HERE    
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results" message:@"No 
         results were found" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
         [alert show];
         return;
    }
    return [self.listItems count]; 
}
于 2013-03-05T06:33:57.807 回答
0

检查 if 条件后写 return 语句。

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

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

    }  
return [self.listItems count];   
于 2013-03-05T06:34:18.650 回答