CooperRS / RMActionController

This is an iOS control for presenting any UIView in an UIAlertController like manner
MIT License
539 stars 59 forks source link

The view of an RMActionController has been loaded before a contentView has been set - iOS 9 #9

Closed Supertecnoboff closed 8 years ago

Supertecnoboff commented 8 years ago

Hi,

Thank you for making this great library. I just have problem, I keep getting the following error:

Error: The view of an RMActionController has been loaded before a contentView has been set. You have to set the contentView before presenting a RMActionController.

Here is my code:

-(void)display_choice_alert {

    // Create the custom alert view actions.
    RMAction *main_action = [RMAction actionWithTitle:@"Pizza menu" style:RMActionStyleDefault andHandler:^(RMActionController *controller) {

        NSLog(@"1");
    }];

    RMAction *side_action = [RMAction actionWithTitle:@"Side orders menu" style:RMActionStyleDefault andHandler:^(RMActionController *controller) {

        NSLog(@"2");
    }];

    RMAction *dismiss = [RMAction actionWithTitle:@"Dismiss" style:RMActionStyleCancel andHandler:^(RMActionController *controller) {
        NSLog(@"3");
    }];

    // Set the custom alert view properties and actions.
    RMActionController *actionController = [RMActionController actionControllerWithStyle:RMActionControllerStyleBlack selectAction:main_action andCancelAction:dismiss];

    // Add additional actions to the custom alert.
    [actionController addAction:side_action];

    // Set the custom alert details.
    actionController.title = @"Test";
    actionController.message = @"This is a test action controller.\nPlease tap 'Select' or 'Cancel'.";

    // Display the custom alert view.
    [self presentViewController:actionController animated:YES completion:nil];
}

Can you tell me what I am doing wrong here? I just followed your example thats all.

Thanks for your time, Daniel.

CooperRS commented 8 years ago

Hi,

As mentioned in the readme file you have to subclass RMActionController. In this subclass you have to set the contentView property to a view of your choice. You may take a look at the example project in this repository ;)

Best regards, Roland

golopupinsky commented 8 years ago

Is there any reason to make overriding mandatory? Wouldn't default implementation make it easier to use? Just having two lines of code in RMActionController initWithStyle would make it usable 'out of the box' without necessity to subclass.

self.contentView = [[UIView alloc] initWithFrame:CGRectZero];
self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
CooperRS commented 8 years ago

Hey!

The problem is what a default implementation would be displaying: It would display an empty view with a set of more or less unrelated buttons. Such a control would not make much sense as an UIAlertController can be used for displaying buttons in a similar manner.

Also subclassing offers you a better way to use the generics offered by RMActionController. You can a generic type in the subclass instead of defining it when initializing the RMActionController.

Best regards, Roland