为什么在ios中过滤数据后在表视图中搜索显示空白表视图?

时间:2014-04-09 06:50:16

标签: ios objective-c uitableview

当我在表视图中搜索时,它提供了正确的数组,我使用NSPredicate来过滤数组。即使在调试时我才知道,它转到cellForRowAtIndexPath并且标签有数据并且一切正常但结果只显示了纯白色的默认表视图,而不是搜索后应该是的表。 / p>

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
preferredCustomCell *mycell = (preferredCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

UIView *backgroundView = [[UIView alloc] initWithFrame:mycell.selectedBackgroundView.frame];
[backgroundView setBackgroundColor:[UIColor colorWithRed:189/255.f green:189/255.f blue:189/255.f alpha:0.25]];
[mycell setSelectedBackgroundView:backgroundView];
SearchbackView.hidden = YES;

// Configure the cell...
if (mycell == nil) {
    mycell = [[preferredCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

MyData *dealerData = Nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
    dealerData = [searchResults objectAtIndex:indexPath.row];
} else {
    dealerData = [cellData objectAtIndex:indexPath.row];
}

dealerInfo = [NSString stringWithFormat:@"%@\n%@\n%@%@%@%@%@\n%@\n%@", dealerData.businessName, dealerData.address, dealerData.city,@", ", dealerData.state, @", ", dealerData.zip, dealerData.phone, dealerData.email];  // data.address;

mycell.dealerInfoLbl.text = dealerInfo;
mycell.dealerInfoLbl.numberOfLines = 0;

mycell.selectDealerBtn.tag = indexPath.row;

// Assign our own background image for the cell
UIImage *background = [UIImage imageNamed:@"selectedCell"];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
mycell.selectedBackgroundView = cellBackgroundView;
mycell.lblPreferred.hidden = YES;

if (mycell.selectDealerBtn.tag==btnTag) {
    if (selectDealer==true) {
        [mycell.selectDealerBtn setImage:[UIImage imageNamed:@"selectedDealer"] forState:UIControlStateNormal];
        [mycell.selectDealerBtn setTitle:@"Select" forState:UIControlStateNormal];
        mycell.selectDealerBtn.imageEdgeInsets = UIEdgeInsetsMake(6, 16, 26, 17);
        mycell.selectDealerBtn.titleEdgeInsets = UIEdgeInsetsMake(32,-66, 0, 10);
        mycell.lblPreferred.hidden = NO;
    }
}
else{
    [mycell.selectDealerBtn setImage:[UIImage imageNamed:@"N99-selectDealerBtn"] forState:UIControlStateNormal];
    [mycell.selectDealerBtn setTitle:@"   " forState:UIControlStateNormal];
    mycell.lblPreferred.hidden = YES;
}

return mycell;

0 个答案:

没有答案