在我的應用程序,它有很多的ViewController類以及tableviewcontroller班我想告訴navigationcontroller具有如何在iphone中使用靜態方法使用self.navigationitem屬性?
//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];
我想在每堂課的上方顯示navigatedtoolbar所有類。爲此我必須在每個類中編寫這段代碼,但是我想刪除重複,我定義了一個具有靜態方法的類,我嘗試在此方法中執行該操作,但生成錯誤,我可以做些什麼來簡要提供一些指導。