导航控制器和工具栏问题



我有一个带有两个视图的导航控制器。第一个视图是带有 TableView 的 ViewController,第二个视图是带有一些 UILabels和UIWebView 的 UIView。从表视图中选择单元格时,导航控制器将推送到第二个视图。

我在导航控制器和一些按钮中添加了一个 UIToolBar。

我的

问题是当导航控制器推送到第二个视图(UIView)时,我的UIToolBar出现了,但没有按钮。

我想显示不同的按钮或从第二个视图中删除 UIToolBar。我想我需要在应用程序代表中做一些事情,我只是不确定什么以及如何做。

这是我的 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

任何帮助将不胜感激。谢谢

您必须为加载到堆栈上的每个视图指定工具栏项。 所以

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

我不能把你说清楚。 我建议这个假设。如果你想在下一个视图的顶部栏中添加按钮,你不要为此使用工具栏。您可以在导航栏本身中添加按钮。您可以使用 AddSubView 方法添加按钮。使用 initwithframe 初始化 UI按钮。然后将其添加为导航控制器的子视图。[导航控制添加子视图:按钮];

最新更新