指示应用程序在加载时打开哪个视图?

发布于 2024-10-24 16:05:05 字数 801 浏览 0 评论 0原文

我试图指示我的应用程序打开某个视图,具体取决于用户是否已经在我的数据库上创建了用户配置文件。

所以基本上 -

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恬淡成诗 2024-10-31 16:05:05

-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文