Iphone 从UIViewController更改为UITableViewController
这个让我发疯。我正在构建一个iphone应用程序,其中第一个视图是登录视图。UIViewController,当用户成功登录时,我希望显示i表视图。不知怎的,我在做这件事时遇到了很大的困难 在我的应用程序委托中,我加载我的loginViewController,然后我想从loginViewController加载我的listViewControllerIphone 从UIViewController更改为UITableViewController,iphone,cocoa-touch,uikit,Iphone,Cocoa Touch,Uikit,这个让我发疯。我正在构建一个iphone应用程序,其中第一个视图是登录视图。UIViewController,当用户成功登录时,我希望显示i表视图。不知怎的,我在做这件事时遇到了很大的困难 在我的应用程序委托中,我加载我的loginViewController,然后我想从loginViewController加载我的listViewController 从UIViewController切换到UITableViewController背后的逻辑是什么?您最好在应用程序代理中执行此操作,当然不要将
从UIViewController切换到UITableViewController背后的逻辑是什么?您最好在应用程序代理中执行此操作,当然不要将UITableViewController.view添加到UIViewController.view。。。只需将其添加到UIWindow,然后关闭旧的UIViewController(从SuperView移除它的视图,然后释放它) 编辑: 我就是这样管理的: 我在appDelegate中添加了一个方法:
-(void)switchMainView;
在我的UIViewController中,我用以下命令调用它:
[[[UIApplication sharedApplication] delegate] switchMainView];
在我看来,我只是
从superview中删除我的UIViewController.view,
释放UIViewController,
分配UITableViewController并初始化它,然后
将其视图添加到Windows应用程序:
-(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];
}
然后我对返回进行了同样的操作,最终你最好在你的应用程序委托中执行,当然不要将UITableViewController.view添加到UIViewController.view中。。。只需将其添加到UIWindow,然后关闭旧的UIViewController(从SuperView移除它的视图,然后释放它) 编辑: 我就是这样管理的: 我在appDelegate中添加了一个方法:
-(void)switchMainView;
在我的UIViewController中,我用以下命令调用它:
[[[UIApplication sharedApplication] delegate] switchMainView];
在我看来,我只是
从superview中删除我的UIViewController.view,
释放UIViewController,
分配UITableViewController并初始化它,然后
将其视图添加到Windows应用程序:
-(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];
}
然后我回去也会这样做,最后你可以用两种方法中的一种,我不认为有什么重大影响,但肯定它们比其他方法有一些优势/劣势 为了更好地理解,请阅读下面的教程
你可以使用这两种方法中的任何一种,我不认为会产生重大影响,但它们肯定会比其他方法有一些优势/劣势 为了更好地理解,请阅读下面的教程
假设您已经创建了自定义UITableViewController:
YourTableViewController *vc = [[UITableViewController alloc] initWithStyle:...];
[self presentModalViewController:vc animated:YES];
[vc release];
假设已创建自定义UITableViewController:
YourTableViewController *vc = [[UITableViewController alloc] initWithStyle:...];
[self presentModalViewController:vc animated:YES];
[vc release];
所以一个很好的方法是在应用程序代理中注册一个通知,然后在用户登录并再次更改应用程序代理中的视图时发送通知?或者可以直接从loginViewController运行app delegate中的方法吗?因此,一个很好的方法是在app delegate中注册通知,然后在用户登录并再次更改app delegate中的视图时发送通知?或者可以直接从loginViewController运行应用程序委托中的方法吗?我建议使用另一种方法从tableviewcontroller打开loginViewController。这样,您可以检查用户是否已登录viewDidLoad,如果未登录,则通过presentModalViewController显示loginViewController。您可以创建一个协议并在tableViewController上实现它,loginViewController调用一个方法让tableViewController知道用户已登录。我建议使用另一种方法从tableViewController打开loginViewController。这样,您可以检查用户是否已登录viewDidLoad,如果未登录,则通过presentModalViewController显示loginViewController。您可以创建一个协议并在tableViewController上实现它,loginViewController调用一个方法,让tableViewController知道用户已登录。