2015-11-20 99 views
0

我用pushViewController:動畫:方法在UIViewController去B UIViewController,並且兩個UIViewController有selfs xib文件。自定義UIBarButtonItem與接口生成器

在系統默認情況下,我不需要改變任何東西,我可以從B UIViewController返回一個UIViewController。

但我想定製我的後退按鈕,我用像後續代碼解決方案:

- (void)initBarButton { 
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)]; 

    self.navigationItem.leftBarButtonItem = cancelButton; 

    UIBarButtonItem *updateButton = [[UIBarButtonItem alloc] initWithTitle:@"Update" style:UIBarButtonItemStyleDone target:self action:@selector(save)]; 

    self.navigationItem.rightBarButtonItem = updateButton; 
} 

- (void)cancel { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

就像這一點,但我想改變,在Interface Builder中修改了廈門國際銀行文件,要做到這一點。我嘗試使用這樣的:

enter image description here

但系統默認的導航欄蓋,當我隱藏系統默認條,滑動手勢(回去喜歡流行的行動)也將被刪除。

是否有任何可能的方法來做我想要的?

順便說一句,我用自動佈局的界面生成器中的導航欄,我怎麼能讓它看起來像這樣的系統默認導航欄(填補狀態欄差距)?

enter image description here

回答

0

是否有任何真正的原因以編程方式做到這一點?看起來你應該能夠完成你想要做的所有事情。

+0

在某些情況下,我不想使用故事板,所以我想知道這一點。 –

0

馬庫斯吳如果您想使用廈門國際銀行,而不是故事板爲實現這一點,你可以看到下面的步驟

1.Remove the storyboard from the project 
2.Also delete the Main from Main Interface of Deployment Target of Project Target. 
3.Now create the New User Interface(View or Empty) and give name as ViewController 
4.Then click the Placeholder File Owner with right side Identity Inspector 
5.In identity Inspector Custom Class -> Class ->Click the drop down and choose the ViewController. 
6.Then Click right side connections inspector. 
7.Click the empty circel(name is View) in Outlet.Drag this to the view.I mean you need to press control+emptycircle and drag it to the View. 

8.in appDelegate.h 
    Import - #import "ViewController.h" 
    @property (strong, nonatomic) ViewController *vc; 

9.In appDelegate.m 
    @synthesize vc; 
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
     // Override point for customization after application launch. 
     self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; 
     vc = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil]; 
     UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:vc]; 
     navigationVC.navigationBarHidden = YES; 
     self.window.rootViewController = navigationVC; 
     self.window.backgroundColor = [UIColor clearColor]; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } 

10.Now in xib create the custom button Back programmatically or from objects(drag button and give connection) 

如果你用故事板,你只需要取消選中的節目導航欄。

1.First Click NavigationController in stroyboard 
2.Click the Attributes Inspector of Right side 
3.Then Click Navigation Controller 
4.Inside the Navigation Controller 
    UnTick the Bar Visibility - Shows Navigation Bar 
5.Now create the custom button programmatically or drag it from the Object Library to ViewController in XIB