Iphone – uitableview reloadData issue

iphonetableviewuisearchbaruitableviewuiviewcontroller

I've been debugging my iphone app and found something interesting.

I have a UIViewControllers with TabBarcontroller( 6 tabs). Each tab is a UIViewController and it has a UITtableview. The viewDidLoad works and brings the initial data. On of the UITableView has a search bar. After the user touchs presses search some magic happens and I get an array with data. I cant see the new data in the tableview and the [tableView reloadData] has no effect outside viewDidLoad (first time).

I can see the array holding the data and the dataSource is set to self. Yet, no displaying of data!

so I 've tried [self.tableView reloadData] & [self.tableView setNeedsDisplay]

Funny enough, the new data is not being displayed. However if I move the table up or down the cellForRowAtIndexPath is being fired and the first row shows data.

can anyone shed some light on this mystery???

if there a [self.view refreshscreen] ??

-(void) viewWillAppear:(BOOL)animated{
    [self.tableView reloadData];
    [super viewWillAppear:animated];    
}

- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar2 {   
    [self searchForFullNames];
        //NSAssert(tableView, @"Whoops, tableView is Null");
    [tableView reloadData];
        // hide keyboard
    [searchBar2 resignFirstResponder];
}
- (void)viewDidLoad {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"search" ofType:@"plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];  
    self.names = dict;
    [dict release];
    NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
    self.keys = array;
    isSearchOn = NO;
    canSelectRow = NO;

    self.tableView.scrollEnabled = NO;

    [super viewDidLoad];
}



- (void) searchForFullNames {

    self.listData = nil;
    self.names = nil;
    self.keys = nil;

    NSMutableDictionary *dict = [[NSMutableDictionary alloc]  init];
    NSMutableArray *person = [[NSMutableArray alloc] init];

    [person addObject:@"Doe, John"];
    [person addObject:@"11234"];    
    [person addObject:@"11/22/75"]; 

    [dict setObject:person forKey:@"Person 1"];

    person = [[NSMutableArray alloc] init];

    [person addObject:@"Doe, Mary"];
    [person addObject:@"4321"]; 
    [person addObject:@"11/22/85"]; 

    [dict setObject:person forKey:@"Person 2"];

    person = [[NSMutableArray alloc] init];

    [person addObject:@"Doe, John"];
    [person addObject:@"336655"];   
    [person addObject:@"10/22/84"]; 

    [dict setObject:person forKey:@"Person 3"];

    self.names = dict;

    [dict release];
        NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
    self.keys = array;

    isSearchOn = NO;
    canSelectRow = YES;

}

Best Solution

UISearchDisplayController has its own tableView property called searchResultsTableView. If you are using a searchDisplayController, try using:

[searchDisplayController.searchResultsTableView reloadData];
Related Question