Pregunta

Ya he publicado mi problema en este problema, pero no tengo mi respuesta perfectamente. Aquí voy a explicar mi problema en otro momento, es muy importante para mí, así que a cualquier costo tengo que resolverla. Ahora mi problema es. ..

Supongamos que tengo 4 tabbaritem en un tabbarController y elementos "tablero", "pedido", "producto", "cliente".

Cada elemento de estos tabar es una llamada respectiva uiviewcontroller.

Dashboar llamando "DashboarviewController";

Llamada de pedido "OrderViewController";

Llamada al producto "ProductViewController";

Cliente llamando a "CustomerViewController";

Ahora tengo que establecer un desplazando a Menubar en cada UiviewController y esta barra de menú que contiene 4 botones. Estos nombres de botones son los mismos que el nombre de los elementos de TabBar "Panel de tablero", "Orden", "Producto", "Cliente".

Ahora, cuando presiono el botón de la barra de menú, el controlador respectivo mostrará lo mismo que para los elementos TabBar. Supongamos que estoy presionando el elemento TabBar de "orden", entonces mostrará el "OrderViewController". Cuando vea este controlador de vista, también me mostrará esa barra de menú en la parte superior del botón ViewController.now, si hago clic en el botón "Producto" en este "OrderViewController", entonces me enviará a mí "ProductViewController".

Eso significa que el elemento y el botón de TabBar del Scroll Menubar funcionarán lo mismo.

Todavía ahora he hecho estos, mi imagen de publicación anterior¿Cómo puedo hacer el mismo botón en el controlador de vista múltiple?

Si algunos saben cómo pueden hacer eso, explíquelo paso a paso. No necesito darle ningún código. Solo explíquelo paso a paso, ¿cómo puedo hacerlo después de leer mi publicación anterior?

Gracias de antemano.

¿Fue útil?

Solución

Ja, ja, ja ..... fue muy divertido cuando lo resolví. Lo que sea que resolviera este problema de una manera diferente, no utilicé el controlador de botón ScrollView para el controlador, en cada controlador que he hecho funciones donde los botones dentro de un ScrollView Crear y en acción del botón Acabo de cambiar el índice seleccionado del controlador TabBar.

en -(void)viewDidload Escribí este código

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

Aquí está el botón Creación y acción

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

}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top