2012-04-18 103 views
0

我有一個導航控制器,兩個視圖。第一個視圖是帶有TableView的ViewController,第二個視圖是帶有一些UILabels和UIWebView的UIView。從TableView中選擇一個單元格時,導航控制器將轉到第二個視圖。NavigationController和工具欄問題

我添加了一個UIToolBar到導航控制器和一些按鈕。

我的問題是,當導航控制器推到第二個視圖(UIView的),我UIToolBar但似乎沒有按鈕。

我想無論是顯示不同的按鈕或從第二視圖中刪除UIToolBar。 我想我需要在AppDelegate內部做些什麼,我只是不確定是什麼以及如何。

這裏是我的XIBS怎麼看:

MainWindow 
- App Delegate 
- Window 
- Navigation Controller 
-- Navigation Bar 
-- ToolBar 
-- View Controller 
--- Bar Button Item 
--- Navigation Item 
---- Bar Back Item 

ViewController 
-TableView 

DetailView 
-View 
--Web View 
--Label 
--Label 

代碼:

AppDelgate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate> 
{ 
UIWindow *window; 
UINavigationController *navigationController; 
UIToolbar *toolBar; 
} 

@property (nonatomic, strong) IBOutlet UIWindow *window; 
@property (nonatomic, strong) IBOutlet UINavigationController *navigationController; 
@property (nonatomic, strong) IBOutlet UIToolbar *toolBar; 

@end 

AppDelegate.m

@implementation AppDelegate 

@synthesize window; 
@synthesize navigationController; 
@synthesize toolBar; 

- (void)applicationDidFinishLaunching:(UIApplication *)application {  

// Override point for customization after app launch  

[window addSubview:[navigationController view]]; 

[window makeKeyAndVisible]; 

} 

- (void)applicationWillTerminate:(UIApplication *)application { 
// Save data if appropriate 
} 

@end 

任何幫助,將不勝感激。由於

回答

2

你必須爲每個視圖加載到堆棧指定toolBarItems。所以,

-(void)viewDidLoad{ 
    [self setToolbarItems:myArrayOfItems]; 
    //do this in every view controller 
    //other code. 
} 
0

我不能讓你清楚。我建議這與假設。如果你想在nextview方法的頂部欄中添加按鈕,你不要使用工具欄。您可以在導航欄本身添加按鈕。 您可以使用addsubview方法添加按鈕。 使用initwithframe初始化UIbutton。然後將其添加爲導航控制器的子視圖。 [navigationcont addsubview:button];