最初我有一个自定义 NavigationBar,没有导航控制器。我有一个滑动菜单。
在主屏幕上有一个带有列表的表格视图。我希望能够将项目添加到此列表中。所以,我不得不在事后添加一个导航控制器。我将导航控制器添加到情节提要中并将其链接到我的主视图控制器[带有列表的那个]。然后我拖入一个视图控制器。我将一个条形按钮项放入导航项,并将其推送到最近添加的视图控制器。
我运行了我的应用程序,该应用程序现在没有显示任何导航栏或导航项。最初我有一个自定义导航栏。
我不太确定这里发生了什么。谢谢你的帮助。
- (void)customizeAppearance {
UIImage *NavBG = [UIImage imageNamed:@"nav bar.png"];
[[UINavigationBar appearance] setBackgroundImage:NavBG forBarMetrics:UIBarMetricsDefault];
从 .m 初始化视图控制器代码
#import "initViewController.h"
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
@interface initViewController ()
@end
@implementation initViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Main"];
}
从.h
#import "ECSlidingViewController.h"
@interface initViewController : ECSlidingViewController
@end
来自 main.m
#import "MainViewController.h"
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
{
NSArray *toDoList;
NSIndexPath *selectedIndexPath;
}
@synthesize menuBtn;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
来自 main.h
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
}
@property (strong, nonatomic) UIButton *menuBtn; // go to MenuViewController.m and synthesize
@end
第二个视图 controller.m 文件
#import "SecondViewController.h"
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize menuBtn;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Below is the same stuff pasted from MainViewController.m
// Do any additional setup after loading the view.
self.view.layer.shadowOpacity = 0.75f;
self.view.layer.shadowOpacity = 10.0f;
self.view.layer.shadowColor = [UIColor blackColor].CGColor;
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
self.menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
menuBtn.frame = CGRectMake(8, 10, 34, 24);
[menuBtn setBackgroundImage:[UIImage imageNamed:@"menuButton.png"] forState:UIControlStateNormal];
[menuBtn addTarget:self action:@selector(revealMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.menuBtn];
}
这是我使用的所有数组