Мне нужно динамически добавить UIViewController, который содержит панель навигации с несколькими кнопками. Когда одна из кнопок нажата, мне нужно поменять отображаемый вид на другую, сохранив навигационную панель.
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];
Теперь, когда кто-то нажимает кнопку Two, я хотел бы удалить viewOne и добавить объект ViewControllerTwo
- (void) showTwo:(id)sender{
ViewControllerTwo* viewTwo = [[ViewControllerOne alloc] init];
[viewOne.view setFrame:[[UIScreen mainScreen] applicationFrame]];
// remove viewOne from m_navViewController and add viewTwo
}
Другими словами, я хочу показать разные виды, нажав один из элементов на панели навигации, но сохранив одну и ту же панель навигации для всех видов.
Обратите внимание, что панель навигации будет содержать пять кнопок. Я упростил это в целях объяснения.
Заранее спасибо.