У меня есть следующий метод, который загружает ячейки в мою таблицу. Ячейка с текстом «Нет результатов» повторяется при прокрутке. Что я делаю не так с выводом из очереди?
- (UITableViewCell *)tableView:(UITableView *)iTableView cellForRowAtIndexPath:(NSIndexPath *)iIndexPath {
static NSString *kCellID = @"cellID";
UITableViewCell *aCell = [iTableView dequeueReusableCellWithIdentifier:kCellID];
if (aCell == nil) {
aCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellID] autorelease];
}
if (iTableView == self.searchDisplayController.searchResultsTableView) {
if (self.isSearching) {
static NSString *aProgressIdentifier = @"SearchProgress";
aCell = [iTableView dequeueReusableCellWithIdentifier:aProgressIdentifier];
if (!aCell) {
aCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aProgressIdentifier] autorelease];
}
aCell.userInteractionEnabled = NO;
UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectZero];
aLabel.text = @"Searching...";
aLabel.font = [UIFont systemFontOfSize:16.0f];
aLabel.textColor = [UIColor grayColor];
aLabel.textAlignment = UITextAlignmentCenter;
[aLabel sizeToFit];
aLabel.frame = CGRectMake(floorf((self.view.frame.size.width / 2.0f) - (aLabel.frame.size.width / 2.0f)), floorf((aCell.frame.size.height / 2.0f) - (aLabel.frame.size.height / 2.0f)), aLabel.frame.size.width, aLabel.frame.size.height);
[aCell addSubview:aLabel];
[aLabel release];
UIActivityIndicatorView *aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[aCell addSubview:aSpinner];
aSpinner.frame = CGRectMake(floorf((aCell.frame.size.width / 2.0f) - (aSpinner.frame.size.width / 2.0f)) - floorf(aLabel.frame.size.width / 2.0f) - 20.0f, floorf((aCell.frame.size.height / 2.0f) - (aSpinner.frame.size.height / 2.0f)), aSpinner.frame.size.width, aSpinner.frame.size.height);
[aSpinner startAnimating];
[aSpinner release];
} else {
Class anObject = [self.masterArray objectAtIndex:iIndexPath.section];
if ([anObject isKindOfClass: [NSArray class]]) {
NSArray *sectionArray = [self.masterArray objectAtIndex:iIndexPath.section];
if (sectionArray.count > 0) {
id aCellObject = [sectionArray objectAtIndex:iIndexPath.row];
if ([aCellObject isKindOfClass:[CMACustomer class]]) {
CMACustomer *aCustomerObject = aCellObject;
aCell.textLabel.
text = aCustomerObject.customerFullName;
aCell.detailTextLabel.text = nil;
} else if ([aCellObject isKindOfClass:[CMAReservation class]]) {
CMAReservation *aReservationObject = aCellObject;
aCell.textLabel.text = aReservationObject.fullName;
aCell.detailTextLabel.text = aReservationObject.orderDescription;
// aCell.detailTextLabel.text = aReservationObject.reservationTimeAndDate;
}
} else {
aCell.userInteractionEnabled = NO;
UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectZero];
aLabel.text = @"No Results.";
aLabel.font = [UIFont systemFontOfSize:16.0f];
aLabel.textColor = [UIColor grayColor];
aLabel.textAlignment = UITextAlignmentCenter;
[aLabel sizeToFit];
aLabel.frame = CGRectMake(floorf((self.view.frame.size.width / 2.0f) - (aLabel.frame.size.width / 2.0f)), floorf((aCell.frame.size.height / 2.0f) - (aLabel.frame.size.height / 2.0f)), aLabel.frame.size.width, aLabel.frame.size.height);
[aCell addSubview:aLabel];
[aLabel release];
}
}
}
} else {
NSString *aLocalizedTitle = [[self.defaultScopeArray objectAtIndex:iIndexPath.row] objectForKey:@"localizedTitle"];
NSString *aDefaultTitle = [[self.defaultScopeArray objectAtIndex:iIndexPath.row] objectForKey:@"defaultTitle"];
aCell.textLabel.text = CMALocalizedStringWithDefaultValue(aLocalizedTitle, aDefaultTitle);
if ([[[self.currentScopeArray objectAtIndex:iIndexPath.row] objectForKey:@"enabledByDefault"] boolValue]) {
aCell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
aCell.accessoryType = UITableViewCellAccessoryNone;
}
}
return aCell;
}