Search code examples
iosobjective-cuistoryboardsegue

How do I get rid of the notification about view presenting on top of each other?


I have a button that does a Segue to another view, so there is no code or action connected to the button it is all done using storyboards, but in the prepareForSegue.

I have added a check in case a specific value is NULL, and the check works as expected but I do get this warning at runtime

2017-04-16 14:50:03.653 NWMobileTill[34117:830763] Warning: Attempt to present <TenderListView: 0x7ff81870b280>  on <TransactionListView: 0x7ff818738530> which is already presenting <UIAlertController: 0x7ff81864fff0>

I don't like runtime warnings or compiler warnings in general, so what do I need to do to get rid of this warning but still keep my check in place when the button is clicked?

This is the prepareForSegue snippet

if ([[segue identifier] isEqualToString:@"trListViewToTenderList"]) {
    if([NWTillHelper getCurrentOrderNumber] == nil) {
        //Step 1: Create a UIAlertController
        UIAlertController *userInfoCheck = [UIAlertController alertControllerWithTitle:@"Tender"
                                                                               message: @"No active transaction, you need to have an active transaction before you can add tenders!"
                                                                        preferredStyle:UIAlertControllerStyleAlert];

        //Step 2: Create a UIAlertAction that can be added to the alert
        UIAlertAction* ok = [UIAlertAction
                             actionWithTitle:@"OK"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 [userInfoCheck dismissViewControllerAnimated:YES completion:nil];

                             }];

        //Step 3: Add the UIAlertAction ok that we just created to our AlertController
        [userInfoCheck addAction: ok];

        //Step 4: Present the alert to the user
        [self presentViewController:userInfoCheck animated:YES completion:nil];
        return;
    }

    TenderListView *destViewController = segue.destinationViewController;
    destViewController.tenderListViewAmountToPayStr = _transactionListViewUberTotalSumLbl.text;
}

Solution

  • You cannot present a view controller (such as a UIAlertController) in prepareForSegue. At that point the segue is committed and you can't change the view presentation.

    In order to perform validation, show an alert and potentially cancel the navigation you should implement shouldPerformSegueWithIdentifier