Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get if/else statement to work
    primarykey
    data
    text
    <p>I have a modal view that comes up requiring the user to verify his/her email before continuing. This modal view can be presented from two different spots in the app. In one spot it comes from another modal view. This is my code for dismissing both modal views at once (works great).</p> <pre><code>MYUser *thisUser = [MyUser thisUser]; [thisUser refreshInBackgroundWithBlock:^(MyObject *thisUser, NSError *error) { if (thisUser){ if ([[thisUser objectForKey:@"emailVerified"] intValue]) { [self dismissViewControllerAnimated:YES completion:^{ MyLoginViewController *controller = (MyLoginViewController *)self.presentingViewController; [controller verifiedEmail]; } }]; } else { NSLog(@"Not verified"); } } else { NSLog(@"%@", error); } }]; </code></pre> <p>The problem starts when I try to add a check incase it doesn't come from another modal view. I have tried inserting this if statement into my <code>dismissViewControllerAnimated:complete:^</code> block:</p> <pre><code>* if ([self.presentingViewController respondsToSelector:@selector(verifiedEmail)]){} if ([self.presentingViewController isMemberOfClass:[MyLoginViewController class]]){} * if ([self.presentingViewController class] == [MyLoginViewController class]){} </code></pre> <p>None of these work. They either fail (in the event of the *'d ones) or crash the app. I'm thinking the issue is because <code>self.presentingViewController</code> isn't typecast, but if I <code>NSLog(@"%@", [self.presentingViewController class]);</code> and <code>NSLog(@"%@", [MyLoginViewController class]);</code>, the output looks identical.</p> <p>Any ideas? Thanks.</p> <p><strong>EDIT WITH SOLUTION</strong></p> <p>It turns out that you cannot call <code>self.presentingViewController</code> inside the completion block because it is <code>null</code> at that point. I modified the code to this:</p> <pre><code>MYUser *thisUser = [MyUser thisUser]; id presentingVC = self.presentingViewController; [thisUser refreshInBackgroundWithBlock:^(MyObject *thisUser, NSError *error) { if (thisUser){ if ([[thisUser objectForKey:@"emailVerified"] intValue]) { [self dismissViewControllerAnimated:YES completion:^{ if ([presentingVC isMemberOfClass:[MyLoginViewController class]]){ MyLoginViewController *controller = (MyLoginViewController *)presentingVC; [controller verifiedEmail]; } }]; } else { NSLog(@"Not verified"); } } else { NSLog(@"%@", error); } }]; </code></pre> <p>And it is now working wonderfully. Thanks for getting me pointed in the right direction!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload