uitableview reloadData问题 [英] uitableview reloadData issue

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

问题描述

我一直在调试我的iPhone应用程序,发现了一些有趣的东西.

I've been debugging my iphone app and found something interesting.

我有一个带有TabBarcontroller(6个标签)的UIViewControllers.每个选项卡都是一个UIViewController,并且具有UITtableview.viewDidLoad起作用并带来初始数据.UITableView的上有一个搜索栏.在用户触摸按键后,搜索发生了一些不可思议的变化,然后我得到了一个包含数据的数组.我在tableview中看不到新数据,并且[tableView reloadData]在viewDidLoad外部无效(第一次).

I have a UIViewControllers with TabBarcontroller( 6 tabs). Each tab is a UIViewController and it has a UITtableview. The viewDidLoad works and brings the initial data. On of the UITableView has a search bar. After the user touchs presses search some magic happens and I get an array with data. I cant see the new data in the tableview and the [tableView reloadData] has no effect outside viewDidLoad (first time).

我可以看到保存数据的数组,并且dataSource设置为self.但是,没有数据显示!

I can see the array holding the data and the dataSource is set to self. Yet, no displaying of data!

所以我尝试了[self.tableView reloadData]&[self.tableView setNeedsDisplay]

so I 've tried [self.tableView reloadData] & [self.tableView setNeedsDisplay]

很有趣,没有显示新数据.但是,如果我向上或向下移动表格,则将触发cellForRowAtIndexPath,并且第一行显示数据.

Funny enough, the new data is not being displayed. However if I move the table up or down the cellForRowAtIndexPath is being fired and the first row shows data.

有人能揭开这个谜吗???

can anyone shed some light on this mystery???

如果有[self.view刷新屏幕] ??

if there a [self.view refreshscreen] ??

-(void) viewWillAppear:(BOOL)animated{
    [self.tableView reloadData];
    [super viewWillAppear:animated];    
}

- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar2 {   
    [self searchForFullNames];
        //NSAssert(tableView, @"Whoops, tableView is Null");
    [tableView reloadData];
        // hide keyboard
    [searchBar2 resignFirstResponder];
}
- (void)viewDidLoad {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"search" ofType:@"plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];  
    self.names = dict;
    [dict release];
    NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
    self.keys = array;
    isSearchOn = NO;
    canSelectRow = NO;

    self.tableView.scrollEnabled = NO;

    [super viewDidLoad];
}



- (void) searchForFullNames {

    self.listData = nil;
    self.names = nil;
    self.keys = nil;

    NSMutableDictionary *dict = [[NSMutableDictionary alloc]  init];
    NSMutableArray *person = [[NSMutableArray alloc] init];

    [person addObject:@"Doe, John"];
    [person addObject:@"11234"];    
    [person addObject:@"11/22/75"]; 

    [dict setObject:person forKey:@"Person 1"];

    person = [[NSMutableArray alloc] init];

    [person addObject:@"Doe, Mary"];
    [person addObject:@"4321"]; 
    [person addObject:@"11/22/85"]; 

    [dict setObject:person forKey:@"Person 2"];

    person = [[NSMutableArray alloc] init];

    [person addObject:@"Doe, John"];
    [person addObject:@"336655"];   
    [person addObject:@"10/22/84"]; 

    [dict setObject:person forKey:@"Person 3"];

    self.names = dict;

    [dict release];
        NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
    self.keys = array;

    isSearchOn = NO;
    canSelectRow = YES;

}

推荐答案

UISearchDisplayController有自己的tableView属性,称为searchResultsTableView.如果您使用的是searchDisplayController,请尝试使用:

UISearchDisplayController has its own tableView property called searchResultsTableView. If you are using a searchDisplayController, try using:

[searchDisplayController.searchResultsTableView reloadData];

这篇关于uitableview reloadData问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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