开发者

popToRootViewControllerAnimated in alertView callback problem

I have a data download process in my app that is initiated by a button click. The operation occurs on a background thread, so the user is free to navigate to other views and do as she likes.

When the download completes, and alert is shown to the user saying that the app needs to be reloaded. When OK is clicked, the alertView clickedButtonAtIndex method is run. Inside this method I call popToRootViewControllerAnimated.

If I have not navigated to other views, and have stayed on the view that the user initiated the download from, this works!! The problem is that if the user has navigated away from the download initiated view and开发者_如何学Python clicks OK on the "reload app" alert, nothing happens. The user is not redirected back to the root view controller. It just stays in place...

Can anyone help? Am I approaching this the wrong way? I need a process that either restarts the app or goes back to my root view controller, no matter where the user has navigated to after the download button was clicked.

Worst case I will just shut the app down and tell the user that they need to restart to apply updates. I would rather steer clear of this and allow the user to stay in the app.

Thanks for your help.

UPDATE:

Here's the code as requested:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != 0) {
    //User indicated that they want to restart the app so that they can apply the update

    cameFrom = CAME_FROM_RESTART;

    [self.navigationController popToRootViewControllerAnimated:NO]; 


     }


You can use setViewController:animated: instead of popToRootViewControllerAnimated. When the last one didnt work to me I use setViewController:animated: and works. The last time that I used setViewController with animated YES, it makes an error. forwarding. If it happens to you try with animated:NO


You might also try setting a Notification to be sent to your singleton app delegate that is called when the download is done or the button is clicked ok or whatever. Then in this callback, you can reload to whatever view controller you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜