Showing Waiting Alert View At Load

前端 未结 4 1618
不知归路
不知归路 2021-01-24 12:47

I would like when my app starts for it to show an Alert view for about 5 seconds, then depending on the outcome of a background process, it will show another Alert view.

相关标签:
4条回答
  • 2021-01-24 13:02

    You can use performSelector:withObject:afterDelay: method instead.

    0 讨论(0)
  • 2021-01-24 13:07

    Don't use sleep on the main thread. Ever. Also don't update UI from a background thread.

    What you want to do is to display your alert on the main thread and return.

    Then, when your networking code completes, have it send a message to the main thread. In the main thread, when you receive a notice that it's done, remove the alert.

    0 讨论(0)
  • 2021-01-24 13:12

    It's not working right because you are trying to tell the main thread of the app to sleep. If you are telling that thread to sleep, then you're most likely not going to allow any UI updating to occur during that time, because all UI updating happens on the main thread.

    What you need to do is move the code for showing the second UIAlertView to a second method, and then call the method - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay, passing it that second method for the selector, and giving it a delay of 5 seconds. Make sure you remove the call to sleep the main thread.

    However, this still seems like a bad practice, because this action should be occurring as a result of your background task completing. So if you can, you should be running the code to show the second alert view upon completion of that task, which most likely could finish in varying amounts of time.

    0 讨论(0)
  • 2021-01-24 13:14

    you block the main thread in you way.

    i think it seems that you just want the user not to do anything before the first 5 sec(to let you connection connect successfully?), if so, lots ways could do that, e.g. just show a view on the top of the window, until you want the user can do something, you can show the disappear button on that view or just disappear it immediately.

    0 讨论(0)
提交回复
热议问题