Permalink
Browse files

UIAlertView+mxcl

  • Loading branch information...
1 parent ac4a25f commit 2ad755ed6aff70120da387ca22dcf4dca8fb3081 @mxcl committed Sep 6, 2011
Showing with 29 additions and 0 deletions.
  1. +1 −0 MBCategories.h
  2. +1 −0 MBCategories.m
  3. +6 −0 UIAlertView+mxcl.h
  4. +21 −0 UIAlertView+mxcl.m
View
@@ -5,4 +5,5 @@
#import "NSURLConnection+mxcl.h"
#import "UIAlertView+mxcl.h"
#import "UIColor+mxcl.h"
+#import "UIAlertView+mxcl.h"
#import "UITableView+mxcl.h"
View
@@ -5,4 +5,5 @@
#import "NSURLConnection+mxcl.m"
#import "UIAlertView+mxcl.m"
#import "UIColor+mxcl.m"
+#import "UIAlertView+mxcl.m"
#import "UITableView+mxcl.m"
View
@@ -0,0 +1,6 @@
+#import <UIKit/UIKit.h>
+
+@interface UIAlertView (mxcl)
+// if error is nil, nothing happens, thus you can avoid the `if (error)` if you like
++ (void)showAlertViewForError:(NSError *)error title:(NSString *)title;
+@end
View
@@ -0,0 +1,21 @@
+#import "UIAlertView+mxcl.h"
+
+@implementation UIAlertView (mxcl)
++ (void)showAlertViewForError:(NSError *)error title:(NSString *)title
+{
+ if (error) {
+ NSString *msg = [error localizedDescription];
+ if (error.localizedFailureReason) {
+ msg = [NSString stringWithFormat:@"%@. %@", msg, error.localizedFailureReason];
+ }
+
+ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
+ message:msg
+ delegate:nil
+ cancelButtonTitle:@"Cancel"
+ otherButtonTitles:nil];
+ [alertView show];
+ [alertView release];
+ }
+}
+@end

0 comments on commit 2ad755e

Please sign in to comment.