从已由被调用的viewcontroller导入的视图控制器调用tabbar视图控制器?

时间:2012-01-11 07:47:35

标签: uiviewcontroller uibutton uitabbarcontroller pushviewcontroller

也许是一个愚蠢的问题,但我必须尽快做到。我的问题是:

我有四个tabbar控制器A,B,C,D,这些控制器在导航栏中导入了一个viewcontroller(假设名称按钮控制器)。

因此,A,B,C,D在A,B,C,D #import buttonViewController.h的每个.h文件中导入此按钮视图控制器,如tabbar controller

现在的问题是,在buttonViewController我有一个按钮,该动作调用“A”tabbar controller或“B”,“C”或“D”tabbar controller

我已经在每个A,B,C,D buttonViewController添加了tabbarcontroller

我该怎么做?

1 个答案:

答案 0 :(得分:0)

哈哈哈......当我解决它时,它真是太有趣了。无论我以不同的方式解决了这个问题,我都没有使用scrollview按钮控制器来控制器,在每个控制器中我都将功能发挥到了哪里滚动视图中的按钮创建和按钮的操作我只需更改选项卡控制器的选定索引。

-(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];   

这里是按钮创建和操作

-(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];

}
相关问题