GSAlertView

/* * Header File */ @interface GSAlertView : UIAlertView<UIAlertViewDelegate> @property (copy) void(^completionBlock)(UIAlertView *alertView, NSInteger buttonIndex); @property (copy) void(^completionBlockWithText)(UIAlertView *alertView, NSInteger buttonIndex, NSString* text); - (void)showWithCompletion:(void(^)(UIAlertView *alertView, NSInteger buttonIndex))completion; - (void)showWithInputTextAndCompletion:(void(^)(UIAlertView *alertView, NSInteger buttonIndex, NSString* text))completion; @end /* * M file */ @implementation GSAlertView - (void)showWithCompletion:(void(^)(UIAlertView *alertView, NSInteger buttonIndex))completion{ self.completionBlock = completion; self.delegate = self; [self show]; } -(void)showWithInputTextAndCompletion:(void(^)(UIAlertView *alertView, NSInteger buttonIndex, NSString* text))completion{ self.alertViewStyle = UIAlertViewStylePlainTextInput; self.completionBlockWithText = completion; self.delegate = self; [self show]; } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ //self.completionBlock(alertView,buttonIndex); } -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{ if(self.completionBlock){ self.completionBlock(alertView,buttonIndex); } else if(self.completionBlockWithText) { self.completionBlockWithText(alertView,buttonIndex,[alertView textFieldAtIndex:0].text); } }
UIAlertView with blocks

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.