3

I have an UIViewController from which I am presenting a modal view.

[self presentViewController:modal animated:YES completion:nil];

It has two UIBarButtonItems (named Cancel and Save). I am performing some action on Save button tap. I am displaying SVProgressHUD Indicator on -saveButtonTapped method.

- (IBAction)saveButtonTapped:(id)sender
{
    NSLog(@"Modal Save Pressed.");
    [SVProgressHUD showWithStatus:@"Loading..."];
    // Some other code...
}

The problem is that the indicator is not displaying in front of my ModalView. It starts animating but behind the ModalView, not in front.


What is happening :

UIViewController ===> SVProgressHUD ===> ModalView

What I want :

UIViewController ===> ModalView ===> SVProgressHUD


I searched but didn't find any solution for that.

Why this is happening and how to solve this issue ?

Bhavin
  • 27,155
  • 11
  • 55
  • 94
  • can you give some images how it's representation – codercat Nov 27 '13 at 12:36
  • @iDev : I can't but I have added the code if it can help you. – Bhavin Nov 27 '13 at 12:45
  • can you provide some screenshots or some additional codes inside your modalcontroller. – Bordz Nov 27 '13 at 12:52
  • @Bordz : I don't think that requires at all. The code that I used is only of one line that I already mentioned in my Question. – Bhavin Nov 27 '13 at 12:54
  • Just some more questions: How is your modal view presented (which type of presentation)? The code added is in the ModalView, correct? does the `saveButtonPressed` dismiss your view as well? Might be related to `previousKeyWindow` not set to your modal view. – Paul Peelen Nov 27 '13 at 12:59
  • @PaulPeelen : 1) `UIModalPresentationFormSheet`, 2) Yes, 3) No – Bhavin Nov 27 '13 at 13:01
  • Did you try showing the HUD at any other time? Like in the view did load of your modal view? – Marc Nov 27 '13 at 13:07
  • @MarcMosby : yeah.. I tried in viewDidLoad. But the same result, not showing in foreground. – Bhavin Nov 27 '13 at 13:11
  • Did you try using segues instead of pushing manually? In my apps I have very similar scenarios and they all work, but I use storyboard. – Marc Nov 27 '13 at 13:17
  • @Vin try debugging on line 448-457 in SVProgressHUD.m. For debugging purposes you could make sure those lines are run when pressing the button in the modalView. The problem seems to be that the `overlay` is not being set to the `modalView`. I believe this was use previously using `previousKeyWindow`. – Paul Peelen Nov 27 '13 at 13:33
  • @PaulPeelen: I debugged and found that those lines are running perfectly. – Bhavin Nov 27 '13 at 13:40
  • @MarcMosby: No, I have not tried with segues. I am using nibs. – Bhavin Nov 27 '13 at 13:42
  • I am not worrying about if the lines are working, but if they are propperly set to the modalView. I made a test project with the same setup as you explained above, however I can't recreate it. So, some further questions: Is the modal view in a UINavigationController or is the modalview directly opened from the UIViewController? Is the UIViewController an modalview as well? – Paul Peelen Nov 27 '13 at 13:48
  • @PaulPeelen : No `UIViewController` is not a modalview. It is just a simple ViewController with NavigationBar. – Bhavin Nov 27 '13 at 13:50
  • Ok, by that I understand that the `UIViewController` exists in a `UINavigationController`. I can't recreate the problem using an `UINavigationController` either. I think you have to show more code since you seem to do something that messes up the window view hierarchy. – Paul Peelen Nov 27 '13 at 13:56
  • @PaulPeelen: I really don't think so. Btw tell me what did you get as a result when you made a test project. – Bhavin Nov 27 '13 at 14:00
  • I got the correct result. The HUD showing in front of all views. I put it quickly together withing a few minutes, so don't look at the code. Here is my source: https://www.dropbox.com/s/cbb8hhvp8kg6ozd/testSVP.zip. Uses the cocoapods lib, so open the workspace file (incase you are not familiar with cocoapods). In this one I change the opening to open from `UINavigationController` but tested even your solution. Try testing opening from nav yourself, and see if it solves your problem. – Paul Peelen Nov 27 '13 at 14:05
  • @PaulPeelen: Ok. Thanks for the help. Let me re-check all the code line by line from the starting if i missed something. – Bhavin Nov 27 '13 at 14:13
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/42041/discussion-between-paul-peelen-and-vin) – Paul Peelen Nov 27 '13 at 14:13
  • So, did you solve it in the end? – Paul Peelen Nov 29 '13 at 14:11

1 Answers1

0

Finally, I got to manage the issue using NSThread.

Actually, I was calling one method named -postForEditDispatch from my -saveButtonTapped method. I created one separate thread using -detachNewThreadSelector:toTarget:withObject: and tried to call that method on that thread.

Sample Code :

- (IBAction)saveButtonTapped:(id)sender
{
    NSLog(@"Modal Save Pressed.");
    [SVProgressHUD showWithStatus:@"Loading..."];
    // Some other code...

    [NSThread detachNewThreadSelector:@selector(postForEditDispatch:) toTarget:self withObject:nil];
}
Bhavin
  • 27,155
  • 11
  • 55
  • 94