我有一个具有此 cellForRowAtIndexPath 方法的应用程序:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = nil;
//IF NO STORES FOUND
if ([self.annotationsToSort count] == 0) {
NSLog(@"No results");
cell.nameLabel.text = @"No results";
}
// Check to see whether the normal table or search results table is being displayed
//IF ITS A SEARCH TABLE....>>>>>>>>>
if (tableView == self.searchDisplayController.searchResultsTableView) {
static NSString *CellIdentifier = @"HolidayCell";
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Location *location = [filteredResultsArray objectAtIndex:indexPath.row];
cell.nameLabel.text = location.nombrePublico;
} else {
// IF ITS A REGULAR TABLE...>>>>>>>>>>
static NSString *CellIdentifier = @"HolidayCell";
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
//cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
}
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//USING SORTED ARRAY INSTEAD OF CDfetched ARRAY
MyLocation *myLocation = [self.annotationsToSort objectAtIndex:indexPath.row];
cell.nameLabel.text = myLocation.name;
cell.dateLabel.text = myLocation.address;
cell.distancia.text = distance;
cell.phoneLabel.text = myLocation.telefono;
cell.openLabel.text = myLocation.estado;
cell.driveThruLabel.text = myLocation.driveThru;
}
return cell;
}
但即使数据中没有结果,它也会返回没有我的 NO RESULTS 文本的空单元格。行方法是:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [filteredResultsArray count];
} else {
//return [self.farSiman count]; WAS CRASHING
return [self.annotationsToSort count];
}
}
我已经尝试将 NO STORES FOUND 代码块放在 NORMAL STATE TABLE if/else 中,但这不起作用。