UITable is not getting populated with NSMutableArray

时光毁灭记忆、已成空白 提交于 2019-12-08 05:41:59

问题


In my app i have a text field where if i enter a word i should get all the file names starting with the particular word into a UITable. Here i am getting these file names into an array and its available in NSLog too... But the table remains empty always. Control is not entering into table(NSLog in tables method is not getting displayed). Can anyone help me? my code is

-(IBAction)Do_Search:(id)sender
{ 
 files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
         [[NSBundle mainBundle] bundlePath] error:nil];
search_results_array = [files filteredArrayUsingPredicate:
                        [NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] 'h'"]];
NSLog(@"%@", search_results_array);
int search_res_count=[search_results_array count];
NSLog(@"Array has %d results...",search_res_count);
[Result_table reloadData];
}

here i couldn't implement the search as i desired. Instead i tried to list all file names starting with "h".

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section          {
    return [search_results_array count];

}

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
 {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
NSString *Lyrics_found= [search_results_array objectAtIndex:indexPath.row];
cell.textLabel.text=Lyrics_found;
NSLog(@"%@",search_results_array);
return cell;
}

when [Result_table reloadData]; is given program gets exited and when removes it the table remains empty.


回答1:


Retain search_results_array before [Result_table reloadData];.



来源:https://stackoverflow.com/questions/9091810/uitable-is-not-getting-populated-with-nsmutablearray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!