Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone uitableview重新加载数据问题_Iphone_Uiviewcontroller_Uitableview_Uisearchbar_Tableview - Fatal编程技术网

Iphone uitableview重新加载数据问题

Iphone uitableview重新加载数据问题,iphone,uiviewcontroller,uitableview,uisearchbar,tableview,Iphone,Uiviewcontroller,Uitableview,Uisearchbar,Tableview,我一直在调试我的iphone应用程序,发现了一些有趣的东西 我有一个带有TabBarcontroller(6个选项卡)的UIViewController。每个选项卡都是一个UIViewController,它有一个UITableView。viewDidLoad工作并带来初始数据。UITableView的上有一个搜索栏。在用户触摸按search之后,一些神奇的事情发生了,我得到了一个包含数据的数组。我无法在tableview中看到新数据,[tableview reloadData]在viewDid

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

我有一个带有TabBarcontroller(6个选项卡)的UIViewController。每个选项卡都是一个UIViewController,它有一个UITableView。viewDidLoad工作并带来初始数据。UITableView的上有一个搜索栏。在用户触摸按search之后,一些神奇的事情发生了,我得到了一个包含数据的数组。我无法在tableview中看到新数据,[tableview reloadData]在viewDidLoad(第一次)之外没有任何效果

我可以看到保存数据的数组,并且数据源设置为self。然而,没有显示数据

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

有趣的是,新数据没有显示出来。但是,如果我向上或向下移动表格,则会触发cellForRowAtIndexPath,第一行显示数据

有人能解释一下这个谜吗

是否有[self.view刷新屏幕]

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

}

您所描述的行为(新数据在滚动之前不会显示)正是我所期望的,如果您没有在表视图上调用reloadData。我将设置一些断点,并确保在右边的UITableView上确实调用了重载数据,并且由于重载数据而调用了CellForRowatineXpath


一种猜测是您的self.tableView IBOutlet未连接,并且self.tableView为空。可能是tableview委托和数据源已连接,但tableview本身未连接。

如果不在table view上调用reloadData,您所描述的行为(新数据在滚动之前不会显示)正是我所期望的。我将设置一些断点,并确保在右边的UITableView上确实调用了重载数据,并且由于重载数据而调用了CellForRowatineXpath


一种猜测是您的self.tableView IBOutlet未连接,并且self.tableView为空。tableview委托和数据源可能已连接,但tableview本身没有连接。

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

[searchDisplayController.searchResultsTableView reloadData];

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

[searchDisplayController.searchResultsTableView reloadData];


viewDidLoad仅在加载视图控制器时调用一次。您可能希望在每次显示视图时(例如切换选项卡时)都更新表,将重新加载的数据调用放入视图将显示。

viewDidLoad仅在加载视图控制器时调用一次。您可能希望在每次显示视图时更新表(例如,当您切换选项卡时),将重新加载的数据调用放在视图中将显示。

您可以执行NSAsset(self.tableView,@“哎呀,tableView为null”);在[self.tableView reloadData]之前;为了测试tableView插座未连接的理论。Brad,***在-[SearchView searchBarSearchButtonClicked:]中的断言失败,SearchView.m:234***WebKit在webView:shouldInsertText:replacingDOMRange:givenAction:delegate:Whoops中丢弃了一个未捕获的异常,tableView为空不确定这是我期望看到的,但看起来NSAssert失败了。。正当而tableView为空??您可以执行NSAsset(self.tableView,@“哎呀,tableView为空”);在[self.tableView reloadData]之前;为了测试tableView插座未连接的理论。Brad,***在-[SearchView searchBarSearchButtonClicked:]中的断言失败,SearchView.m:234***WebKit在webView:shouldInsertText:replacingDOMRange:givenAction:delegate:Whoops中丢弃了一个未捕获的异常,tableView为空不确定这是我期望看到的,但看起来NSAssert失败了。。正当并且tableView是空的??我没有使用searchDisplayCOntroller,但是谢谢!!!我在所有FileOwner下都看到了它,但从未使用过。你知道我在哪里可以找到一些示例代码来实现它吗??谢谢这可能对他没有帮助,但它确实帮助我解决了我的问题+1格洛里菲德哈克!令人惊叹的我遇到了一个问题,搜索结果集在旋转后没有正确更新。在“didRotateFromInterfaceOrientation”中调用此委托方法后,问题已得到解决+1到@glorifiedHacker.
MLReceiptonListTable.m:209:17:未知接收器“searchDisplayController”;你是说“UISearchDisplayController”吗?
但它生成错误。我没有使用searchDisplayCOntroller,但谢谢!!!我在所有FileOwner下都看到了它,但从未使用过。你知道我在哪里可以找到一些示例代码来实现它吗??谢谢这可能对他没有帮助,但它确实帮助我解决了我的问题+1格洛里菲德哈克!令人惊叹的我遇到了一个问题,搜索结果集在旋转后没有正确更新。在“didRotateFromInterfaceOrientation”中调用此委托方法后,问题已得到解决+1到@glorifiedHacker.
MLReceiptonListTable.m:209:17:未知接收器“searchDisplayController”;您是说“UISearchDisplayController”吗?
但它生成错误。ViewWillDisplayController只调用一次。当我单击选项卡栏和切换选项卡时,它从未被调用。ViewWillDisplay只被调用一次。当我单击选项卡栏和切换选项卡时,它从未被调用。通常,当您调用super的方法时,您会将该调用放在要重写的方法的开头(Dealoc是一个明显的例外)。在执行自己的设置之前,请调用[super viewDidLoad];否则,您可能会无意中破坏自己的设置。你的ViewWillDisplay实现也是如此。你发布[self SearchForFullName]的代码怎么样?很抱歉。。我总是忘记添加代码!!:)问题在于,搜索似乎是为存储在内存中的数据而设计的。我想找回
[self.searchDisplayController.searchResultsTableView reloadData];