UITable не заполняется NSMutableArray - PullRequest
1 голос
/ 01 февраля 2012

В моем приложении у меня есть текстовое поле, где, если я введу слово, я получу все имена файлов, начиная с конкретного слова, в UITable.Здесь я получаю эти имена файлов в массив, и он также доступен в NSLog ... Но таблица всегда остается пустой.Элемент управления не входит в таблицу (метод NSLog в таблицах не отображается).Может кто-нибудь мне помочь?мой код

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

when [Result_table reloadData];данная программа выходит из программы, а при ее удалении таблица остается пустой.

1 Ответ

1 голос
/ 01 февраля 2012

Сохранить search_results_array до [Result_table reloadData];.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...