Reputation: 315
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.
Upvotes: 1
Views: 201