2013-02-05 316 views
-1

最初我有一個自定義NavigationBar,沒有導航控制器。我有一個滑動菜單。添加導航控制器,但不顯示導航項目

在主屏幕上有一個tableview和一個列表。我希望能夠將項目添加到此列表中。所以,我必須在事實之後添加一個導航控制器。我將導航控制器添加到故事板,並將其鏈接到我的主視圖控制器[帶有列表的那個控制器]。然後我拖入一個視圖控制器。我將一個酒吧按鈕項放入導航項中,並將其推送到最近添加的視圖控制器。

我跑了我的應用程序,應用程序現在顯示沒有任何導航欄或導航項目。最初我有一個自定義導航欄。

我不太確定這裏發生了什麼事。謝謝你的幫助。

- (void)customizeAppearance { 
    UIImage *NavBG = [UIImage imageNamed:@"nav bar.png"]; 
    [[UINavigationBar appearance] setBackgroundImage:NavBG forBarMetrics:UIBarMetricsDefault]; 

My storyboard

從.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]; 
} 

這裏是所有陣列我用

All arrays

回答

-1

從你呈現,它的圖像看起來不像任何風險投資家有左起始箭頭。如果是這種情況,請轉到SB,單擊導航控制器,轉到右側的屬性檢查器,向下滾動並選中「是初始視圖控制器」。

希望這回答它。

更新:在您的代碼中猜測,您正嘗試修改不可變的NSArray。將您的聲明更改爲NSMutableArray * toDoList。

+0

它引發了一個異常「由於未捕獲的異常'NSInvalidArgumentException'終止應用程序,原因:'*** - [__ NSArrayM insertObject:atIndex:]:object can not be nil'」 – STANGMMX

+0

您也看不到它,但是最左邊是一個初始視圖控制器 – STANGMMX

+0

你能展示更多的代碼嗎?這看起來很明顯與NSArray有關。另外,init View控制器如何推送到Nav? – Spectravideo328