2015-11-20 3 views
0

Я использовал pushViewController: анимированный: метод в A UIViewController для перехода к B UIViewController, а два UIViewController имели собственный файл xib.Пользовательский UIBarButtonItem с построителем интерфейса

В системе по умолчанию мне ничего не нужно было менять, и я могу вернуться обратно UIViewController из B 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]; 
} 

Так же, как это, но я хочу, чтобы изменить это в интерфейсе строителя модифицированного файла XIb, чтобы сделать это , Я пытаюсь использовать это как:

enter image description here

Но навигационная панель по умолчанию системы покрытия, когда я скрыть панель системы по умолчанию, салфетки жест (вернуться, как поп-акции) также будут удалены.

Можно ли сделать то, что я хочу?

BTW, я использовал панель навигации в построителе интерфейса с автоматической компоновкой, как я могу позволить ей выглядеть как панель навигации по умолчанию системы, подобная этому (заполнить пробел в строке состояния)?

enter image description here

ответ

0

Есть ли реальная причина сделать это программно? Похоже, вы должны быть в состоянии сделать все в построителе интерфейса, который вы хотите сделать.

+0

В некоторых случаях я не хочу использовать доску истории, поэтому я хочу знать об этом. –

0

Маркус В Если вы хотите использовать XIB вместо раскадровки для достижения этой цели, вы можете увидеть ниже шаги

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