I have my app base on navigationController
. So i set the toolbar visible for some views and for others i didnt calling setToolbarHidden:NO
or YES
.
first question, this goes in viewWillAppear
method ?
Then in my appDelegate
, I put one item on the toolbar but is not being show.
can someone show me how can I use delegate protocol here so each view know what to do when a item is pressed??
my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//create itemViewcontroller
EventosViewController *itemsViewController = [[EventosViewController alloc] init];
//create UINavigationcontroller, stack only contains itemviewcontroller
navController=[[UINavigationController alloc] initWithRootViewController:itemsViewController];
//navController will retain itemviewcontroller, we can release it
[itemsViewController release];
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pressButton1:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem,nil];
//release buttons
[systemItem1 release];
[flexItem release];
//add array of buttons to toolbar
[navController.toolbar setItems:items animated:NO];
//set navController's view in window hierarchy
[[self window] setRootViewController:navController];
[navController release];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
thx in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…