views:

46

answers:

4

In my application which have a lot of viewcontroller classes as well as tableviewcontroller classes in all classes i want to show navigationcontroller which have

//creation of toolbar
UIToolbar *tool = [UIToolbar new];
tool.frame = CGRectMake(0, 0, 320, 42);
//create setting button
UIButton *bttn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];
[bttn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *back=[[UIBarButtonItem alloc]initWithCustomView:bttn];

//Space
UIBarButtonItem *spbtn = [[UIBarButtonItem alloc] init];

spbtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
         UIBarButtonSystemItemFlexibleSpace   target:nil action:nil];

//Show Logo
UIButton *bttn1;
bttn1= [UIButton buttonWithType:UIButtonTypeCustom];
bttn1.frame = CGRectMake(20, 0, 230, 30);
bttn1.backgroundColor = [UIColor clearColor];
[bttn1 addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
UIImage *imgss =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"pic" ofType:@"png"]];
UIImage *strechableImage1 = [imgss stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[bttn1 setBackgroundImage:strechableImage1 forState:UIControlStateNormal];
UIBarButtonItem *logo;
logo=[[UIBarButtonItem alloc]initWithCustomView:bttn1];

//assign toolbar into navigation bar
NSArray *items = [NSArray arrayWithObjects:back,logo,spbtn,nil];
[tool setItems:items animated:YES];
tool.barStyle =UIBarStyleBlackOpaque;
tool.backgroundColor = [UIColor clearColor];
self.navigationItem.leftBarButtonItem =  [[UIBarButtonItem alloc] initWithCustomView:tool];

I want to show navigatedtoolbar at top of every class. for this i have to write this code in every class but i want to remove repetition i define a class which have static methods i try to perform that action in this method but its generate error what can i do provide some guidance in brief .

A: 

hey dear check out this link it may be help you http://www.bukisa.com/articles/180100_iphone-core-data-tutorial-part-1

A: 

yes you can use the

Is it possible to use self.navigationbar .

A: 

I find solution its very simple through inheritance concept create a base class which shows navigatedtoolbar and then i use base class as a superclass of file

suchita
A: 

UINavigationController has a toolbar already. If you were to enable that, you can just provide the buttons that should be on the toolbar from the viewControllers. Apple's Mail application uses this concept. A benefit of this that you do not see the toolbar leaving the screen during navigation stack animations which makes it seems like it is sitting on top of everything and button's on the toolbar changes according to the UIViewController that is currently on the screen.

Bittu