2014-03-26 146 views
0

我正在尝试更改应用程序内我正在编辑代码的视图。但是当呈现一个新的视图控制器时,导航栏在特定情况下似乎没有更新。现在的行为看起来是这样的: 我通过单击的TabBar选项卡上导航到tableviewcontroller, 然后我用导航到一个视图控制器从这个tableviewcontroller:与UITabbar UINavigation不起作用

settingsController = [SettingsController create]; 
[self.navigationController pushViewController: settingsController animated: YES]; 

,我相信调用此代码:

+(id)create 
{ 
    SettingsController*settings = [[SettingsController alloc] init]; 
    NSBundle*bundle = [NSBundle bundleForClass: [SettingsController class]]; 
    [bundle loadNibNamed: @"SettingsController" owner: settings options: NULL]; 
    settings.view.frame = CGRectMake(0, 0, 320, 411); 

    settings.title = @"Settings"; 

    return settings; 
} 

然后从那里我导航到另一个视图控制器使用:

SearchViewController*searchView; 
searchView = [[SearchViewController alloc] initWithNibName:@"SearchView" bundle: [NSBundle mainBundle]]; 
    [self presentViewController:searchView animated:YES completion:nil]; 

,这是行为开始变得越来越麻烦,导航栏不会更新到视图控制器中的更改。我没有写这个代码,但它一直在给我头痛,试图清理它。

回答

0

如果您使用的是navigationController那么你不应该叫

[self presentViewController:searchView animated:YES completion:nil];

您应该使用

[self.navigationController pushViewController:searchView animated:YES];

0

此外,它会更好地使用标准的内置函数初始化一个新的视图控制器。

SettingsController*settings = [[SettingsController alloc] initWithNibName:@"SettingsController" bundle:nil]; 
[self.navigationController pushViewController:settings animated:YES]; 

然后在视图控制器中使用默认方法。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    self.title = @"Settings"; 
    //other view changes. 
} 
return self; 
} 
0

查看在您的视图控制器导航控制器初始化tabbarcontroller现在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
UIViewController *viewController1, *viewController2,*viewController3; 
viewController1 = [[ViewController alloc] init]; 
viewController2 = [[FormStatusViewController alloc] initWithNibName:@"FormStatusViewController" bundle:nil]; 
viewController3 = [[DocumentsViewController alloc] init]; 

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController1]; 
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:viewController2]; 
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:viewController3]; 


nav.navigationBarHidden=YES; 
nav1.navigationBarHidden=YES; 
nav2.navigationBarHidden=YES; 


NSArray *viewsArray = [[NSArray alloc] initWithObjects:nav,nav1,nav2, nil]; 
self.formTabBar= [[UITabBarController alloc] init]; 
[self.formTabBar setViewControllers:viewsArray]; 

UITabBar *tabBar = self.formTabBar.tabBar; 
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; 
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2]; 


tabBarItem1.title = @"FORM"; 
tabBarItem2.title = @"STATUS"; 
tabBarItem3.title = @"DOCUMENTS"; 

UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg.png"] 
          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[[UITabBar appearance] setBackgroundImage:tabBackground]; 

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) { 
    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"form.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"form_h.png"]]; 
    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"status.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"status_h.png"]]; 
    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"documents.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"documents_h.png"]]; 
} else { 
    tabBarItem1.selectedImage = [[UIImage imageNamed:@"form_h.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 
    tabBarItem1.image = [[UIImage imageNamed:@"form.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 

    tabBarItem2.selectedImage = [[UIImage imageNamed:@"status_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 
    tabBarItem2.image = [[UIImage imageNamed:@"status.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 

    tabBarItem3.selectedImage = [[UIImage imageNamed:@"documents_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 
    tabBarItem3.image = [[UIImage imageNamed:@"documents.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]; 


} 
[[UITabBar appearance] setSelectionIndicatorImage: 
[UIImage imageNamed:@"tab_select_indicator.png"]]; 

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                [UIColor whiteColor], UITextAttributeTextColor, 
                nil] forState:UIControlStateNormal]; 


[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                [UIColor whiteColor], UITextAttributeTextColor, 
                nil] forState:UIControlStateHighlighted]; 


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.window.rootViewController = self.formTabBar; 
[self.window makeKeyAndVisible]; 

return YES; 
} 

的方式这个例子假设在第一个选项卡的firstviewcontroller要导航到该标签的另一个视图控制器然后使用代码如下

SearchViewcontroller *searchView =[[SearchViewcontroller alloc]init]; 
[self.navigationController pushViewController:searchView animated:YES];