1

我面臨一些嚴重的問題。所以我非常具體地解釋。如何通過按鈕點擊控制tabbar項目?

  1. 兩個視圖控制器A)UITabbar控制器B)包含按鈕滾動視圖的視圖控制器。

  2. 我在A控制器的導航欄上有子視圖B控制器[圖像中的藍色按鈕] [圖像下方圖像的黑色按鈕]。

enter image description here

這是我如何能做到了

scrollButtonView = [[scrollViewButtons alloc] initWithNibName:@"scrollViewButtons" bundle:nil]; 
CGRect frame = CGRectMake(0, 20, 320, 43); 
scrollButtonView.view.frame = frame; 
scrollButtonView.view.userInteractionEnabled =YES; 
[self.navigationController.view addSubview:scrollButtonView.view]; 

代碼現在我的問題是,當我將單擊控制器B的按鈕,然後tabbarbar選擇指數會發生變化,這種觀點控制器將顯示在屏幕上。這意味着當我點擊屏幕頂部的滾動按鈕中的order按鈕時,它將顯示訂單控制器和標籤欄項目索引將會改變,並且與標籤欄控制器相同[A co ntroller]

需要注意的是: A和B兩種控制器將含有相同的觀點按鈕,同樣controller.I不知道該怎麼做呢?我想要詳細的答案。

也可參見:

如果是不可能的,那麼告訴我,我怎樣才能添加按鈕的滾動菜單欄添加的TabBar控制器的每個控制器和滾動按鈕將重定向喜歡的TabBar控制器相同的控制器項目? 現在,我希望我會得到我的解決方案。

+1

你不應該重新發布的問題,你可能想拿下其中的一個,因爲這只是分裂解決問題的人,最終可能會產生一團糟。您可能還想重申您的問題,以包含ios或更廣泛傳播的標籤...... – bardiir 2012-01-11 13:12:43

回答

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

}