Skip to content

Instantly share code, notes, and snippets.

@valvoline
Created January 20, 2015 08:52
Show Gist options
  • Save valvoline/528922fd0e0865599dac to your computer and use it in GitHub Desktop.
Save valvoline/528922fd0e0865599dac to your computer and use it in GitHub Desktop.
Simple category that wraps around the UIAlertController annoying stuff
//
// UIAlertController+Utilities.h
//
// Created by valvoline on 18/12/14.
// Copyright (c) 2014 sofapps. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIAlertController (Utilities)
+ (UIAlertController*)alertControllerWithTitle:(NSString *)aTitle
message:(NSString *)aMessage
actions:(UIAlertAction *)cancelAct,...;
+ (UIAlertController*)sheetControllerWithTitle:(NSString *)aTitle
message:(NSString *)aMessage
actions:(UIAlertAction *)cancelAct, ...;
@end
//
// UIAlertController+Utilities.m
//
// Created by valvoline on 18/12/14.
// Copyright (c) 2014 sofapps. All rights reserved.
//
#import "UIAlertController+Utilities.h"
@implementation UIAlertController (Utilities)
+ (UIAlertController*)alertControllerWithTitle:(NSString *)aTitle
message:(NSString *)aMessage
actions:(UIAlertAction *)cancelAct, ...
{
va_list args;
va_start(args, cancelAct);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:aTitle
message:aMessage
preferredStyle:UIAlertControllerStyleAlert];
for (UIAlertAction *anAct = cancelAct; anAct != nil; anAct = va_arg(args, UIAlertAction*))
{
[alert addAction:anAct];
}
va_end(args);
return alert;
}
+ (UIAlertController*)sheetControllerWithTitle:(NSString *)aTitle
message:(NSString *)aMessage
actions:(UIAlertAction *)cancelAct, ...
{
va_list args;
va_start(args, cancelAct);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:aTitle
message:aMessage
preferredStyle:UIAlertControllerStyleActionSheet];
for (UIAlertAction *anAct = cancelAct; anAct != nil; anAct = va_arg(args, UIAlertAction*))
{
[alert addAction:anAct];
}
va_end(args);
return alert;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment