从UIViewController更改为UITableViewController

时间:2011-03-16 10:33:14

标签: iphone cocoa-touch uikit

这个让我变得疯狂。我正在构建一个iphone应用程序,其中第一个视图是登录视图。 UIViewController,当用户成功登录时,我想显示i表视图。不知何故,我只是遇到了很大的问题。

在我的app委托中,我加载了我的loginViewController,然后我想从loginViewController加载我的listViewController。

从UIViewController切换到UITableViewController背后的逻辑是什么?

3 个答案:

答案 0 :(得分:4)

你最好在你的app委托中执行它,当然不要将UITableViewController.view添加到UIViewController.view ...只需将其添加到UIWindow然后解除旧的UIViewController(removeFromSuperView它的视图然后释放它)

修改

这就是我的管理方式:

我在appDelegate中添加了一个方法:

-(void)switchMainView;

从我的UIViewController我只需用它调用它:

[[[UIApplication sharedApplication] delegate] switchMainView];
我只是在switchMainView中的

 从superview中删除我的UIViewController.view, 发布UIViewController, 然后分配UITableViewController并初始化它 将其视图添加到窗口应用程序:

-(void)switchMainView{
    if (mainView!=nil){ // mainView is the UIViewController
        [mainView.view removeFromSuperview];
        [mainView release];
        mainView = nil;
    }
    Menu *vc; // Menu is my class, subClass of a UITableViewController
    vc = [[Menu alloc] init];
    nc = [[UINavigationController alloc] initWithRootViewController:vc];
    [window addSubview:nc.view];
    [vc release];
}

然后我做同样的回去,最终

答案 1 :(得分:1)

假设您已经创建了自定义UITableViewController:

YourTableViewController *vc = [[UITableViewController alloc] initWithStyle:...];
[self presentModalViewController:vc animated:YES];
[vc release];

答案 2 :(得分:0)

你可以使用我不认为会产生重大影响,但肯定他们可能比其他人有一些优势/劣势..

为了更好地理解,请阅读以下教程。

http://cocoawithlove.com/2009/03/recreating-uitableviewcontroller-to.html