2012-01-10 5 views
-1

私はすでに別の時間に私のこの問題を投稿しましたが、私は完全に私の問題を説明するつもりです、私は非常に重要ですので、私はそれを解決する必要があります。 ...ナビゲーションバーに同じスクロールメニューバーを追加する方法はありますか?

私は、に4 tabbaritemと「ダッシュボード」、「注文」、「製品」、「顧客」という項目があるとします。

これらのタブバーのすべての項目はそれぞれuiviewcontrollerと呼ばれています。

ダッシュボードの呼び出し「DashboarViewController」;

order "orderViewController"を呼び出します。

product "ProductViewController";

カスタマー・コール "CustomerViewController";

ここでは、すべてのuiviewcontrollerと、このメニューバーに4つのボタンが含まれているので、スクロールメニューバーを設定する必要があります。これらのボタン名は、タブバー項目名「ダッシュボード」、「注文」、「製品」、「顧客」と同じです。

ここで、メニューバーのボタンを押すと、それぞれのコントローラはタブバーアイテムと同じように表示されます。私は "注文"タブバーの項目を押すと、それは "orderviewcontroller"を表示すると仮定します。このビューコントローラが表示されると、viewcontroller.Nowの上部にあるメニューバーも表示されます。この「orderviewcontroller」の「product」ボタンをクリックすると、「productViewcontroller」というメッセージが返されます。

これは、スクロールメニューバーのアイテムとボタンの意味が同じになります。いくつかは、それはstep.Iバイステップで説明してくださいが、それを説明するyou.justから任意のコードを与える必要がないことを行うことができます方法を知っていれば今でも私は、私の以前のポスト画像 How can i make same button in multiple view controller?

をこれらを行っている

私の前のポストを読んだ後、それをどうやって行うことができるかを段階的に教えてください。

ありがとうございました。

答えて

0

ハッハッハ.....私はそれを解決したときにとても楽しいものでした。私はこの問題をさまざまな方法で解決しましたが、私はコントローラのスクロールビューのボタンコントローラを使用しませんでした。スクロールビュー内のボタンは、ボタンiの作成時および動作時に、タブバーコントローラの選択されたインデックスを変更するだけである。 -(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]; 

} 
を書きました
関連する問題