有没有在导航栏上添加同样的滚动菜单栏?

我已经把这个问题再次发布了,但是我还没有完全得到我的答案。在这里我要解释我的问题,这对我来说非常重要,所以我不得不解决这个问题。现在我的问题是。 ..

假设,我有tabbaritem中的4个tabbarController和项目“仪表板”,“订单”,“产品”,“客户”。

这些tabbar的每个项目都是一个调用那里各自的uiviewcontroller

dashboar调用“DashboarViewController”;

命令调用“orderViewController”;

产品调用“ProductViewController”;

客户调用“CustomerViewController”;

现在,我必须在每个uiviewcontroller中设置一个滚动菜单栏,并且这个菜单栏包含4个button。 这些button名称与标签栏项目名称“仪表板”,“订单”,“产品”,“客户”相同。

现在当我按菜单栏的button,那么相应的控制器将显示相同的标签栏项目。 假设我按“订单”标签栏项然后它会显示“orderviewcontroller”。 当我将看到这个视图控制器,它也会显示在viewcontroller.Now顶部的菜单栏,如果我点击这个“orderviewcontroller”中的“产品”button,那么它会发回给我“productViewcontroller”。

这意味着tabbar项目和滚动菜单栏的button将工作相同。

仍然现在我已经做了这些,我以前的post图像我怎样才能在多个视图控制器相同的button?

如果有人知道如何做到这一点,请一步一步解释。我不需要给你任何代码,只要一步一步地解释一下,在阅读我以前的文章之后,我该怎么做?

提前致谢。

哈哈哈…..当我解决它是非常有趣的。无论我以不同的方式解决这个问题,我没有使用滚动视图button控制器的控制器只是在每个控制器我已经作出的function,滚动视图创build和button的动作,我只是改变选定的控制器的索引。

-(void)viewDidload我写这个代码

  UIView *scrollViewBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)]; scrollViewBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"topmenu_bg.png"]]; menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(5,0,320,40)]; menuScrollView.showsHorizontalScrollIndicator = FALSE; menuScrollView.showsVerticalScrollIndicator = FALSE; menuScrollView.bounces = TRUE; [scrollViewBackgroundView addSubview:menuScrollView]; [self.view addSubview:scrollViewBackgroundView]; [self createMenuWithButtonSize:CGSizeMake(92.0, 30.0) withOffset:5.0f noOfButtons:7]; 

这里是button创build和操作

 -(void)mybuttons:(id)sender{ NSLog(@"mybuttons called"); UIButton *button=(UIButton *)sender; NSLog(@"button clicked is : %iBut \n\n",button.tag); int m = button.tag; for(int j=0;j<8;j++){ if(button.tag == m){ self.tabBarController.selectedIndex = m; [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_hover.png"] forState:UIControlStateHighlighted]; //sets the background Image] } if(button.tag != m){ [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } } } -(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{ NSLog(@"inserting into the function for menu bar button creation"); for (int i = 0; i < totalNoOfButtons; i++) { UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; [button addTarget:self action:@selector(mybuttons:) forControlEvents:UIControlEventTouchUpInside]; (button).titleLabel.font = [UIFont fontWithName:@"Arial" size:12]; if(i==0){ [button setTitle:[NSString stringWithFormat:@"Dashboard"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_hover.png"] forState:UIControlStateNormal]; //sets the background Image] } if(i==1){ [button setTitle:[NSString stringWithFormat:@"Order"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } if(i==2){ [button setTitle:[NSString stringWithFormat:@"Product"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } if(i==3){ [button setTitle:[NSString stringWithFormat:@"Customers"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } if(i==4){ [button setTitle:[NSString stringWithFormat:@"Content"] forState:UIControlStateNormal];//with title } if(i==5){ [button setTitle:[NSString stringWithFormat:@"Site Analysis"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } if(i==6){ [button setTitle:[NSString stringWithFormat:@"Store Settings"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } if(i==7){ [button setTitle:[NSString stringWithFormat:@"CMS Settings"] forState:UIControlStateNormal];//with title [button setBackgroundImage:[UIImage imageNamed:@"btn_topmenu_normal.png"] forState:UIControlStateNormal]; //sets the background Image] } button.frame = CGRectMake(i*(offset+buttonSize.width), 6.0, buttonSize.width, buttonSize.height); button.clipsToBounds = YES; button.showsTouchWhenHighlighted=YES; button.layer.cornerRadius = 5;//half of the width button.layer.borderColor=[UIColor clearColor].CGColor; button.layer.borderWidth=0.0f; button.tag=i; [menuScrollView addSubview:button]; } menuScrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height); [self.view addSubview:menuScrollView]; }