Skip to content
Roland Moers edited this page Oct 31, 2016 · 14 revisions

This page will describe how to use RMActionController in your project.

Basic

RMActionController does not come with any content view (the one in the middle between all those buttons) for presentation. This means presenting an RMActionController only presents a set of buttons. For this task UIAlertController might be a better option.

The strength of RMActionController is that it can present any UIView as content view in an UIActionSheet/UIAlertController like fashion. To add a content view to RMActionController it is usually subclassed. This project contains two subclasses (RMCustomViewActionController and RMMapActionController) which give two examples for a subclass of RMActionController. In addition, you might want to take a look at the following projects for more examples on how to use RMActionController:

Subclassing

The remainder of this wiki page will explain how to create a subclass of RMActionController.

Creating your subclass

First create your own subclass of RMActionController. I assume you know how to do that. When creating your subclass you can specify a generic type. This type should be set to the class of the content view you are about to show. For example, if you are planning to present an MKMapView, the generic should be set to MKMapView.

Objective-C

@interface RMMapActionController : RMActionController<MKMapView *>
@end

Swift

class MapActionController: RMActionController<MKMapView> {
}

Implementing your subclass

When subclassing RMActionController you only have to overwrite one method. This method is called actionControllerWithStyle:title:message:selectAction:andCancelAction:. For example, your implementation may look like follows:

- (instancetype)initWithStyle:(RMActionControllerStyle)aStyle title:(NSString *)aTitle message:(NSString *)aMessage selectAction:(RMAction *)selectAction andCancelAction:(RMAction *)cancelAction {
    self = [super initWithStyle:style title:aTitle message:aMessage selectAction:selectAction andCancelAction:cancelAction];
    if(self) {
        self.contentView = [[MKMapView alloc] initWithFrame:CGRectZero];
        self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
        self.contentView.accessibilityLabel = @"MapView";
        
        NSDictionary *bindings = @{@"contentView": self.contentView};
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contentView(200)]" options:0 metrics:nil views:bindings]];
    }
    return self;
}

Clone this wiki locally