开发者

Navigation items for navigation controller in interface builder

开发者 https://www.devze.com 2023-02-21 22:58 出处:网络
- i have a FirstViewController and a SecondViewController, each has its xib - in the MainWindow.xib i have a UINavigationController, which is connected to IBOutlet

- i have a FirstViewController and a SecondViewController, each has its xib

- in the MainWindow.xib i have a UINavigationController, which is connected to IBOutlet

- in the AppsDelegate i call

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    FirstViewController * fv = [[FirstViewController alloc] init];

    [navigationController pushViewController:fv animated:NO];

    [fv release];

    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];

    return YES;
}

4) the problem is, when i want to manage Navigation item through interface builder... like for the first view i want to add a button to the right and customize the back text and the title

sure i could do this using code : (by fv.navigationItem.rightBarButtonItem = ... and fv.title=@"...") but i want to achive this in interface builder

  • in my FirstViewController.xib and SecondViewController.xib i add a Navigation item and add the a right Bar item

the problem is, it never shows up and the title doesnt 开发者_Python百科alter

  • if i open MainWindow.xib and add a ViewController (FirstViewController) under the NavigationController (so its listed under it = make it the rootViewController for the NavigationController) and also add Navigation item and Bar Buttom item, whoala, the NavigationBar at the top has the left button

  • again this would be great... BUT i cannot do the same think for the SecondViewController, because in interface builder, there can be only one rootViewController under the Navigation Controller... and again if i add the Navigation item in SecondViewController.xib it doesnt show up:(

- so ho can i manage the Navigation items and Bar button items for multiple ViewControllers in interface builder

(i looked at most tutorial, but they do it inside the code, by .navigationItem.rightBarButtonItem, what i want to avoid)


ok, the best solution i found

is to design the buttons in Interface builder and link them via Outlet, then in code i simply add them

fv.navigationItem.rightBarButtonItem = myOutletButton;

i didnt find a way to do it just only in interface builder so it gets bind automaticly :(


If u like to do a separate NVC please instaniate it not from main view, do this from different view's separate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号