Comment puis-je append plus de 10 buttons sur une barre de navigation dans le développement d'applications iPhone?

Dans mon application, je dois append 8 buttons sur une barre de navigation .. Il est donc tout à fait normal que ces buttons doivent être dans une vue et il devrait y avoir un button précédent et suivant. Quand j'appuierai sur le button suivant, j'utiliserai l'animation pour afficher les buttons suivants qui ne sont pas visibles et identiques à ceux du button précédent.

Pour plus de détails:

  1. UINavigation Bar -> leftBaritem [button précédent] + view + rightBaritem [button suivant];

  2. La vue contiendra 8 buttons. Si je l'explique à nouveau, cela devrait ressembler à ceci:

Précédent + | A | B | C | D | E | F | G | H + suivant

quand j'appuierai

prochain

alors ça va montrer comme ça:

précédent + | B | C | D | E | F | G | H + suivant

comme ça pour

précédent

button.

MODIFIER:

Dans cette image il y a trois button dans une vue mais j'ai six button à append sur la vue "Dashbord, ordre, produit". Maintenant, quand je vais appuyer sur ">" ou "<" ou sur les éléments de la barre gauche / droite, cela affichera les buttons de la barre de navigation qui sont hors de la vue.

entrez la description de l'image ici

Vous faites la mauvaise chose. Vous ne devriez pas essayer de forcer 8 buttons dans une barre de navigation.

Vous devez repenser votre interface. Deux approches raisonnables viennent à l'esprit:

  • Utilisez une barre d'tabs. Une barre d'tabs a le support pour manipuler plus d'options que s'adapteront à l'écran. Par exemple, l'application Musique embeddede comporte 10 tabs.

  • Mettez vos huit buttons dans une vue plein écran sous un controller de navigation. Lorsque l'user en clique un, appuyez sur la vue appropriée pour ce button. L'user peut revenir en arrière (en utilisant le support du button de return normal du controller de navigation) pour choisir un autre button.

J'ai résolu ce problème de manière légèrement différente ….

Dans viewDidLoad j'ai pris un scrollView et appelé ma fonction

 menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,40)]; menuScrollView.showsHorizontalScrollIndicator = FALSE; menuScrollView.showsVerticalScrollIndicator = FALSE; menuScrollView.bounces = TRUE; [self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:7]; 

Puis dans ma function j'ai créé mes buttons menu qui ressembleront à des buttons sur une navigation bar

 -(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]; [button addTarget:self action:@selector(mybuttons:) forControlEvents:UIControlEventTouchUpInside]; if(i==0){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Dashboard"] forState:UIControlStateNormal];//with title } else if(i==1){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Order"] forState:UIControlStateNormal];//with title } else if(i==2){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Product"] forState:UIControlStateNormal];//with title } else if(i==3){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Customers"] forState:UIControlStateNormal];//with title } else if(i==4){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Content"] forState:UIControlStateNormal];//with title } else if(i==5){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Site Analysis"] forState:UIControlStateNormal];//with title } else if(i==6){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"Store Settings"] forState:UIControlStateNormal];//with title } else if(i==7){ [button setTitle:[NSSsortingng ssortingngWithFormat:@"CMS Settings"] forState:UIControlStateNormal];//with title } button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height); button.clipsToBounds = YES; button.showsTouchWhenHighlighted=YES; button.layer.cornerRadius = 0;//half of the width //button.layer.borderColor=[UIColor clearColor]; button.layer.backgroundColor=[UIColor blueColor].CGColor; button.titleLabel.font = [UIFont systemFontOfSize:10]; button.layer.borderWidth=0.0f; button.tag=i; [menuScrollView addSubview:button]; } menuScrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height); [self.view addSubview:menuScrollView]; } 

et ça résout … Happy Coding … :))