如何在多视图控制器中制作相同的按钮? [英] How can i make same button in multiple view controller?
问题描述
可能重复:
- 实现您描述的功能。
滚动视图中的按钮只复制标签栏功能 - 导致令人困惑的用户体验。
Possible Duplicate:
Is there anyway to add same scroll menubar at the navigation bar?May be it is a stupid question but i have to solve it at any cost because my whole project depending on it.My question is,
I have four view controller A, B, C, D.
A has 4 buttons btn1,btn2,btn3,brn4. when i will start click on btn then
btn1 click -> A controller reload or current controller reload;
btn2 click -> B controller open;
btn3 click -> C controller open;
btn4 click -> D controller open;
B has 4 buttons btn1,btn2,btn3,brn4. when i will start click on btn then
btn1 click -> A controller open;
btn2 click -> B controller reload or current controller reload;
btn3 click -> C controller open;
btn4 click -> D controller open;
C has 4 buttons btn1,btn2,btn3,brn4. when i will start click on btn then
btn1 click -> A controller open;
btn2 click -> B controller open;
btn3 click -> C controller reload or current controller reload;
btn4 click -> D controller open;
D has 4 buttons btn1,btn2,btn3,brn4. when i will start click on btn then
btn1 click -> A controller open;
btn2 click -> B controller open;
btn3 click -> C controller open;
btn4 click -> D controller reload or current controller reload;
I need detail process how can i do that?
Thanks In Advance.
EDIT:
All of my these controller (A,B,C,D) are in tabbar controller and buttons are in a scrollview which are at the top of the controller.I have attaching a image of these UI,till now i have done this....
further any query please do not hesitate to ask. Thanks again
EDIT 2:
This is scrollview of button which i have imported in every controller
viewDidload
oftabbar
items.scrollButtonView = [[scrollViewButtons alloc] initWithNibName:@"scrollViewButtons" bundle:nil]; CGRect frame = CGRectMake(0, 20, 320, 43); scrollButtonView.view.frame = frame; scrollButtonView.view.userInteractionEnabled =YES; [self.navigationController.view addSubview:scrollButtonView.view];
here is the code where i want to switch the controller on button click.but problem is when i import those A,B,C,D then i found an error
Unknown controller
-(void)mybuttons:(id)sender{ NSLog(@"mybuttons called"); UIButton *button=(UIButton *)sender; if (button.tag == 0) { NSLog(@"hey have clicked first button, this is my tag : %i \n\n",button.tag); [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_hover.png"] forState:UIControlStateSelected]; //sets the background Image] } else { [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } if (button.tag == 1) { NSLog(@"hey have clicked second button, this is my tag : %i \n\n",button.tag); [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_hover.png"] forState:UIControlStateNormal]; //sets the background Image] self.tabBarController.selectedIndex = 1; } else if (button.tag == 2) { NSLog(@"hey have clicked first button, this is my tag : %i \n\n",button.tag); [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_hover.png"] forState:UIControlStateNormal]; //sets the background Image] //UIViewController *newController = [[UIViewController alloc] initWithNibName:@"CustomerViewController" bundle:nil]; //UINavigationController *myCustomerController = [[[UINavigationController alloc] initWithRootViewController:newController] autorelease]; //UINavigationController *myCustomerController = [[UINavigationController alloc] initWithNibName:@"CustomerViewController" bundle:nil]; UIViewController *secondViewController = [[UIViewController alloc] initWithNibName:@"CustomerViewController" bundle:nil]; [self.navigationController pushViewController:secondViewController animated:YES]; self.tabBarController.selectedIndex = 2; } else if (button.tag == 3) { NSLog(@"hey have clicked second button, this is my tag : %i \n\n",button.tag); [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_hover.png"] forState:UIControlStateNormal]; //sets the background Image] //[self.navigationController pushViewController:cstViewController animated:YES]; self.tabBarController.selectedIndex = 3; } }
EDIT3:
Any way i have to solve the problem so i have tried a lot of way but i missed a simple matter. when i want to change the tap bar then then also i am getting these buttons so i have solved this problem a little bit different way..see my answer you will get the answer..
further any question pls ask. Any how i have to solve the problem.
Thanks In Advance.
解决方案Have you considered using a UITabBarController - that implements the functionality you are describing.
The buttons in the scroll view just replicates the tab bar functionality - resulting in a confusing user experience.
这篇关于如何在多视图控制器中制作相同的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!