0

当应用程序进入后台或再次进入前台时,我想重置我的 UISearch。当 UISearch 中的 tableview 被隐藏时就足够了。

但是当我试图从 AppDelegate.m 中隐藏它时它不起作用。我还记录了 UIElements,还有(null)。

这是我尝试访问它的方法:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
XLog(@"");
/*
 Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
 */

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    XLog(@"");
    searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController_iPad" bundle:[NSBundle mainBundle]];
} else {
    XLog(@"");
    searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController_iPhone" bundle:[NSBundle mainBundle]];
}


XLog(@"searchViewController.searchBar.text: %@", searchViewController.searchBar.text);
searchViewController.tableViewSearch.hidden = YES; // is (null)

XLog(@"searchViewController.tableViewSearch: %@", searchViewController.tableViewSearch); // is (null)

}

我怎样才能访问它?我这里有什么问题,还是不允许通过 appdelegate.m 访问其他类的元素?

4

1 回答 1

2
NSArray *ary_navigationControllerViews = [[NSArray alloc] initWithArray:[self.navigationController viewControllers]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.class.description == %@", [[SearchViewController class] description]];
NSArray *ary_viewController = [[NSArray alloc] initWithArray:[ary_navigationControllerViews filteredArrayUsingPredicate:predicate]];
if ([ary_viewController count] > 0) 
{
   SearchViewController *sVw =  (SearchViewController*) [ary_viewController objectAtIndex:0] ;
  sVw.tableViewSearch.hidden = YES;
}

您正在初始化视图控制器的新实例,而不是您需要获取视图控制器的现有实例并隐藏您的视图。希望这可以帮助。

于 2012-07-30T12:21:35.740 回答