diff --git a/Example/MainWindow.xib b/Example/MainWindow.xib index 610ac8e..71c2775 100644 --- a/Example/MainWindow.xib +++ b/Example/MainWindow.xib @@ -1,14 +1,14 @@ - 1552 - 12E55 - 3084 - 1187.39 - 626.00 + 2048 + 14E46 + 7706 + 1348.17 + 758.70 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 2083 + 7703 IBProxyObject @@ -53,15 +53,15 @@ 0 0 1 - Sample Alert example - - 3 - MQA - 1 MC4xOTYwNzg0MzE0IDAuMzA5ODAzOTIxNiAwLjUyMTU2ODYyNzUAA + + 3 + MQA + + Sample Alert example 3 MC41AA @@ -91,9 +91,9 @@ 0 0 1 - Ice cream Alert example - + + Ice cream Alert example @@ -111,9 +111,28 @@ 0 0 1 - Timed Alert example + + Timed Alert example + + + + + + + 1316 + + {{20, 174}, {280, 44}} + + + NO + IBCocoaTouchFramework + 0 + 0 + 1 + + Textfield with validation example @@ -125,7 +144,6 @@ {{20, 293}, {280, 45}} - NO YES 7 @@ -144,10 +162,11 @@ 1 1 + 0 17 - Helvetica + HelveticaNeue 17 16 @@ -155,7 +174,7 @@ - {320, 460} + {{0, 20}, {320, 460}} @@ -166,13 +185,17 @@ NO NO + + IBUISimulatedFreeformSizeMetricsSentinel + Freeform + IBCocoaTouchFramework YES NO - + delegate @@ -224,6 +247,15 @@ 21 + + + showAlert4WithTextField + + + 7 + + 6UZ-Mw-lch + @@ -257,6 +289,7 @@ + @@ -280,6 +313,11 @@ + + 7jn-vQ-IYZ + + + @@ -301,12 +339,16 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin OHAlertsExampleAppDelegate com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + @@ -353,23 +395,140 @@ IBProjectSource - ./Classes/OHAlertsExampleAppDelegate.h + ../OHAlertsExampleAppDelegate.h + + + + OHAlertsExampleAppDelegate + + id + id + id + id + + + + showAlert1 + id + + + showAlert2 + id + + + showAlert3 + id + + + showAlert4WithTextField + id + + + + IBProjectSource + ../OHAlertsExampleAppDelegate.m + + + + + + UIApplication + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIApplication.h + + + + UIButton + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UIButton.h + + + + UIControl + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIControl.h + + + + UIGestureRecognizer + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIGestureRecognizer.h + + + + UILabel + UIView + + IBFrameworkSource + UIKit.framework/Headers/UILabel.h + + + + UIResponder + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + UIWindow + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIWindow.h 0 IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - + NO com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 YES 3 - 2083 diff --git a/Example/OHAlertsExampleAppDelegate.h b/Example/OHAlertsExampleAppDelegate.h index b4dd50b..b5bc3bf 100644 --- a/Example/OHAlertsExampleAppDelegate.h +++ b/Example/OHAlertsExampleAppDelegate.h @@ -16,6 +16,7 @@ -(IBAction)showAlert1; -(IBAction)showAlert2; -(IBAction)showAlert3; +-(IBAction)showAlert4WithTextField; @end diff --git a/Example/OHAlertsExampleAppDelegate.m b/Example/OHAlertsExampleAppDelegate.m index da1a066..ef3a90e 100644 --- a/Example/OHAlertsExampleAppDelegate.m +++ b/Example/OHAlertsExampleAppDelegate.m @@ -85,6 +85,19 @@ -(IBAction)showAlert3 } +-(IBAction)showAlert4WithTextField +{ + OHAlertView *ohav = [[OHAlertView alloc] initWithTitle:@"Text field" message:@"Email:" cancelButton:@"Cancel" otherButtons:@[@"OK"] buttonHandler:^(OHAlertView *alert, NSInteger buttonIndex) { + + }]; + + [ohav setShouldEnableFirstButton:^BOOL(OHAlertView* alert) { + NSString *email = [alert textFieldAtIndex:0].text; + return (email && email.length > 0); + }]; + ohav.alertViewStyle = UIAlertViewStylePlainTextInput; + [ohav show]; +} ///////////////////////////////////////////////////////////////////////////// // MARK: - diff --git a/OHAlertView/OHAlertView.h b/OHAlertView/OHAlertView.h index 475c58f..f82ada5 100644 --- a/OHAlertView/OHAlertView.h +++ b/OHAlertView/OHAlertView.h @@ -12,7 +12,10 @@ @interface OHAlertView : UIAlertView typedef void(^OHAlertViewButtonHandler)(OHAlertView* alert, NSInteger buttonIndex); +typedef BOOL (^OHShouldEnableFirstOtherButton)(OHAlertView *alert); @property (nonatomic, copy) OHAlertViewButtonHandler buttonHandler; +/** block called by delegate to enable or not the first button, generally 'ok' */ +@property (nonatomic, copy) OHShouldEnableFirstOtherButton shouldEnableFirstButton; ///////////////////////////////////////////////////////////////////////////// diff --git a/OHAlertView/OHAlertView.m b/OHAlertView/OHAlertView.m index 24ef8fd..d61d193 100644 --- a/OHAlertView/OHAlertView.m +++ b/OHAlertView/OHAlertView.m @@ -172,4 +172,14 @@ -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)b } } +-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView { + BOOL enable; + if (self.shouldEnableFirstButton) { + enable = self.shouldEnableFirstButton((OHAlertView *)alertView); + } else { + enable = YES; + } + return enable; +} + @end