NavigationController和工具栏问题
问题描述:
我有一个导航控制器,两个视图。第一个视图是带有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
任何帮助,将不胜感激。由于
答
你必须为每个视图加载到堆栈指定toolBarItems。所以,
-(void)viewDidLoad{
[self setToolbarItems:myArrayOfItems];
//do this in every view controller
//other code.
}
答
我不能让你清楚。我建议这与假设。如果你想在nextview方法的顶部栏中添加按钮,你不要使用工具栏。您可以在导航栏本身添加按钮。 您可以使用addsubview方法添加按钮。 使用initwithframe初始化UIbutton。然后将其添加为导航控制器的子视图。 [navigationcont addsubview:button];