2014-03-26 91 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];