2011-05-03 2 views
0

다중 단추가있는 탐색 모음이 포함 된 UIViewController를 동적으로 추가해야합니다. 버튼 중 하나가 눌려지면 탐색 표시 줄을 유지하면서 표시된보기를 다른보기로 바꿔야합니다. 누군가가 두 버튼을 누를 때 이제IOS 동적으로 생성 된 탐색 모음과 다른보기 표시

CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; 

ViewControllerOne* viewOne = [[ViewControllerOne alloc] init]; 
[viewOne.view setFrame:appFrame]; 

UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44.01)]; 
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3]; 

UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(back:)]; 
[buttons addObject:bi]; 
[bi release]; 

bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
[buttons addObject:bi]; 
[bi release]; 

bi = [[UIBarButtonItem alloc] initWithTitle:@"Two" style:UIBarButtonItemStyleBordered target:self action:@selector(showTwo:)]; 
[buttons addObject:bi]; 
[bi release]; 

[tools setItems:buttons animated:NO]; 
[buttons release]; 
viewOne.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
[tools release]; 

m_navViewController = [[UINavigationController alloc] initWithRootViewController:viewOne]; 
[m_navViewController.view setFrame: appFrame ]; 
[self addSubview: m_navViewController.view]; 

나는 내가 탐색 모음에있는 항목 중 하나를 눌러 다른보기를 표시 할 다른 단어에서 ViewControllerTwo 객체를

- (void) showTwo:(id)sender{ 
    ViewControllerTwo* viewTwo = [[ViewControllerOne alloc] init]; 
    [viewOne.view setFrame:[[UIScreen mainScreen] applicationFrame]]; 

    // remove viewOne from m_navViewController and add viewTwo 
} 

을 viewOne를 제거하고 추가하고 싶습니다 모든보기에 대해 동일한 탐색 막대를 유지하십시오.

탐색 표시 줄에는 실제로 5 개의 버튼이 있습니다. 설명을 위해 단순화했습니다.

미리 감사드립니다.

답변

1

nav 컨트롤러 템플릿을 사용할 수 있습니다. IB의 탐색 표시 줄 (또는 위에서 수행 한 코드)에 단추를 추가하면 해당 단추 중 하나가 탭되면 해당보기 컨트롤러가 누 릅니 다.

+0

예제의 가능성 – user346443

+0

이 코드를 사용하여 각 버튼에 IBAction으로 연결하면됩니다. '[self.navigationController pushViewController : someViewController animated : YES];' – FeifanZ

관련 문제