2012-07-30 26 views
0

我想在应用程序进入后台或重新输入前景时重置我的UISearch。当UISearch的tableview被隐藏时就足够了。如何从Appdelegate方法应用程序重置UISearchWillEnterForeground

但是,当我试图从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访问其他类的元素?

回答

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

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

相关问题