How to switch between different UIViewcontrollers
I want to write a custom switch that will be located two custom tabBar. Its structure is as follows -
I want to use uiviewcontroller.
Now I use the following code:
- (void)changeViewController:(NSInteger)sender{
if(viewController){
[viewController.view removeFromSup开发者_开发知识库erview];
[viewController release];
NSLog(@"released");
}
switch (sender) {
case 1:
viewController = [[VC1 alloc] init];
break;
case 2:
viewController = [[VC2 alloc] init];
break;
case 3:
viewController = [[VC3 alloc] init];
break;
default:
break;
}
[viewController.view setFrame:CGRectMake(0, 100, 320, 380)];
[self.view addSubview:viewController.view];
}
but I think it's wrong!
Can be used in such a structure - presentModalViewController
, dismissModalViewControllerAnimated
or other method to work on the similarity navigationViewController
?
Try this
[self.navigationController pushViewController:viewController animated:YES];
or
[self.view addsubview:viewcontroller.view];
You could try this - [self.navigationController pushViewController:viewController animated:NO];
or [self.navigationController popToViewController:targetController animated:YES];
I would really subscribe navigationController
for its memory management and a far responsive and seamless behaviour...
hope this helps.
精彩评论