2012-02-01 12 views
1

私のアプリでは、単語を入力すると、特定の単語で始まるすべてのファイル名をUITableに入れるテキストフィールドがあります。ここでは、これらのファイル名を配列に入れて、NSLogでも利用できます...しかし、テーブルは常に空のままです。コントロールがテーブルに入力されていません(テーブルメソッドのNSLogは表示されません)。誰でも助けてくれますか? 私のコードはここにUITableにNSMutableArrayが設定されていません

-(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]; 
} 

私は希望として私は、検索を実装することができませんでしたです。代わりに、 "h"で始まるすべてのファイル名をリストしようとしました。

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

} 

//表ビューセルの外観をカスタマイズします。

- (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; 
} 

[Result_table reloadData];与えられたプログラムは終了し、それを取り除くとテーブルは空のままです。

+1

[Result_table reloadData]の前にsearch_results_arrayを保持します。 – Sarah

+0

誓約... gr8 ...ありがとうございました...それは動作します:) :) – priya

+1

コードがクラッシュした場合は、ご質問にクラッシュの詳細を含めてください。これはとても重要です。 – jrturton

答えて

1

保持search_results_array[Result_table reloadData];より前。

関連する問題