1

나는 심각한 문제에 직면하고 있습니다. 그래서 저는 매우 구체적으로 설명하고 있습니다.어떻게하면 단추를 클릭하여 Tabbar 항목을 제어 할 수 있습니까?

  1. 2 개의보기 컨트롤러 A) UITabbar 컨트롤러 B) 스크롤 뷰가있는보기 컨트롤러입니다.

  2. 컨트롤러 [이미지 아래 이미지의 검은 색 버튼]의 탐색 모음에있는 하위보기 B 컨트롤러 [이미지에 파란색 버튼]이 있습니다. 여기

    enter image description here

내가 다음 선택이 변경됩니다 인덱스와 해당 뷰를 tabbarbar 컨트롤러 B의 버튼을 클릭 할 때 이제 내 문제는 내가 그것을
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]; 

했던 방법 코드입니다 컨트롤러가 화면에 표시됩니다. 화면 상단에있는 스크롤 된 버튼에서 order 버튼을 클릭하면 주문 컨트롤러가 표시되고 tabbar 항목 인덱스는 Tabbar 컨트롤러 [A co ntroller]

참고 : 모두 A와 B 컨트롤러가 동일한 뷰 버튼과 같은 controller.I를 포함 할 것이다 그것을 할 수있는 방법을 몰라? 나는 구체적인 방식으로 대답을 원한다.

은 또한 다음과

가 가능하지 않은 경우 다음 내가 버튼의 스크롤 메뉴 표시 줄이 TabBar의 컨트롤러의 모든 컨트롤러를 추가하고 버튼을 스크롤하는 TabBar의 컨트롤러와 같은 동일한 컨트롤러를 리디렉션합니다 추가하는 방법을 말해 항목? 이제 해결책을 찾길 바랍니다.

+1

당신은 당신이 단지 분할로 그들 중 하나를 수행 할 수 있습니다 질문에 대한 재 게시하지 말아야 문제를 해결하는 사람들을 위로하고 결국 엉망진창으로 끝날 수도 있습니다. ios 또는 더 널리 퍼져있는 태그를 포함하도록 질문을 다시 할 수도 있습니다 ... – bardiir

답변

0

하하하 ..... 내가 해결할 때 너무 재미 있었어. 내가이 문제를 다른 방식으로 해결 했더라면, 나는 모든 컨트롤러에서 scrollview 버튼 컨트롤러를 사용하지 않았다. to scrollview 내에서 버튼을 만들고 버튼 i의 동작으로 tabbar 컨트롤러의 선택된 인덱스를 변경했습니다. -(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]; 

} 
관련 문제