如何在不同的UIViewcontroller之间切换
我想编写一个自定义开关,将位于两个自定义 tabBar 上。其结构如下 -
我想使用 uiviewcontroller。
现在我使用以下代码:
- (void)changeViewController:(NSInteger)sender{
if(viewController){
[viewController.view removeFromSuperview];
[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];
}
但我认为这是错误的!
可以在这样的结构中使用 - presentModalViewController
、dismissModalViewControllerAnimated
或其他方法来处理相似性 navigationViewController
吗?
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 removeFromSuperview];
[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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
或
Try this
or
你可以尝试这个 -
[self.navigationController PushViewController:viewControllerAnimated:NO];
或
[self.navigationController popToViewController:targetControlleranimated:YES];
我真的会订阅
navigationController
的内存管理和远响应和无缝行为...希望这会有所帮助。
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.