UITable 没有被 NSMutableArray 填充 [英] UITable is not getting populated with NSMutableArray

查看:55
本文介绍了UITable 没有被 NSMutableArray 填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个文本字段,如果我输入一个单词,我应该将以特定单词开头的所有文件名放入 UITable.在这里,我将这些文件名放入一个数组中,并且它也可以在 NSLog 中使用...但该表始终为空.控件未进入表格(表格中的 NSLog 方法未显示).谁能帮我?我的代码是

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

在这里我无法按照我的意愿实施搜索.相反,我尝试列出所有以h"开头的文件名.

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

当[Result_table reloadData];给定程序退出,当删除它时,表保持为空.

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

推荐答案

[Result_table reloadData];之前保留search_results_array.

这篇关于UITable 没有被 NSMutableArray 填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆