指示应用程序在加载时打开哪个视图?
我试图指示我的应用程序打开某个视图,具体取决于用户是否已经在我的数据库上创建了用户配置文件。
所以基本上 -
- (void) viewWillAppear:(BOOL)animated {
//all my ASIHTTPRequest code here
//blah blah blah
NSString *responseString = [request responseString];
if ([responseString isEqualToString:@"noexistingdata"])
{
FriendsViewController *friendsview = [[FriendsViewController alloc] initWithNibName:nil bundle:nil];
//SOMETHING NEEDS TO GO HERE TO MAKE THIS WORK!
} else if ([responseString isEqualToString:@"success"])
{
//do whatever
}
}
我只想要最基本的更改视图的代码...我会尝试使用 IBAction,但显然这不起作用,因为这对于应用程序的启动来说是无效的(而不是对用户按下的按钮的响应) ),也想过虚空中的虚空,这也行不通。
所以基本上我需要的是:
启动应用程序>应用程序从我的服务器收到响应> (如果响应=“这个”,加载视图“X”)(如果响应=“那个”,加载视图“Y”)
有人有线索吗?
PS:最好列出这是 applicationDidFinishLaunching 吗?
I am trying to instruct my app to open a certain view, depending on whether the user has already created a user profile on my database.
so basically -
- (void) viewWillAppear:(BOOL)animated {
//all my ASIHTTPRequest code here
//blah blah blah
NSString *responseString = [request responseString];
if ([responseString isEqualToString:@"noexistingdata"])
{
FriendsViewController *friendsview = [[FriendsViewController alloc] initWithNibName:nil bundle:nil];
//SOMETHING NEEDS TO GO HERE TO MAKE THIS WORK!
} else if ([responseString isEqualToString:@"success"])
{
//do whatever
}
}
I just want the most basic code for changing a view... I would try using IBAction, but obviously that won't work as this is in a void for the app's launch (rather a response to a button the user presses), also thought about void in a void, which also did not work.
So basically what I need is:
Launch App > App receives response from my server > (IF RESPONSE = "THIS", LOAD VIEW "X") (IF RESPONSE = "THAT", LOAD VIEW "Y")
Anyone have a clue?
PS: would it be better to list this is applicationDidFinishLaunching?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-viewWillAppear:在显示视图之前调用。这可能不是 a) 运行一些同步网络请求和 b) 加载另一个视图控制器的好时机。
我建议让应用程序委托创建一个视图控制器,其视图仅显示一条消息,例如“连接到服务器”或“检索用户凭据”或其他内容。您可以添加一个动画旋转器,让用户知道他们应该等待(如果这是他们此时被允许做的所有事情)。然后,在显示视图后(例如在该控制器的 -viewDidLoad 方法中),启动异步网络连接以与服务器通信。当您收到响应时,决定接下来要实例化哪个视图控制器,然后执行该操作。
-viewWillAppear: is called just before a view is displayed. That's probably not a great time to a) run some synchronous network request and b) load another view controller.
I'd suggest having the application delegate create a view controller who's view just displays a message, like "Connecting to server" or "Retrieving user credentials" or whatever. You might add an animated spinner to let the user know that they're supposed to wait, if that's all they're allowed to do at this point. Then, after the view is displayed, such as in that controller's -viewDidLoad method, start an asynchronous network connection to talk to the server. When you get back a response, decide which view controller to instantiate next, and do that.