Skip to content

Commit

Permalink
Add property block called by delegate to enable (or not) the first ot…
Browse files Browse the repository at this point in the history
…her button.

Useful to validate input text.
  • Loading branch information
Gwendal MOUSSET committed Jul 29, 2015
1 parent e000549 commit 5808938
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 24 deletions.
207 changes: 183 additions & 24 deletions Example/MainWindow.xib
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1552</int>
<string key="IBDocument.SystemVersion">12E55</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.39</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<int key="IBDocument.SystemTarget">2048</int>
<string key="IBDocument.SystemVersion">14E46</string>
<string key="IBDocument.InterfaceBuilderVersion">7706</string>
<string key="IBDocument.AppKitVersion">1348.17</string>
<string key="IBDocument.HIToolboxVersion">758.70</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">2083</string>
<string key="NS.object.0">7703</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
Expand Down Expand Up @@ -53,15 +53,15 @@
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Sample Alert example</string>
<object class="NSColor" key="IBUIHighlightedTitleColor" id="34193676">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor" id="862019999">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MzE0IDAuMzA5ODAzOTIxNiAwLjUyMTU2ODYyNzUAA</bytes>
</object>
<object class="NSColor" key="IBUIHighlightedTitleColor" id="34193676">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<string key="IBUINormalTitle">Sample Alert example</string>
<object class="NSColor" key="IBUINormalTitleShadowColor" id="823323164">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC41AA</bytes>
Expand Down Expand Up @@ -91,9 +91,9 @@
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Ice cream Alert example</string>
<reference key="IBUIHighlightedTitleColor" ref="34193676"/>
<reference key="IBUINormalTitleColor" ref="862019999"/>
<reference key="IBUIHighlightedTitleColor" ref="34193676"/>
<string key="IBUINormalTitle">Ice cream Alert example</string>
<reference key="IBUINormalTitleShadowColor" ref="823323164"/>
<reference key="IBUIFontDescription" ref="95042656"/>
<reference key="IBUIFont" ref="600433790"/>
Expand All @@ -111,9 +111,28 @@
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Timed Alert example</string>
<reference key="IBUINormalTitleColor" ref="862019999"/>
<reference key="IBUIHighlightedTitleColor" ref="34193676"/>
<string key="IBUINormalTitle">Timed Alert example</string>
<reference key="IBUINormalTitleShadowColor" ref="823323164"/>
<reference key="IBUIFontDescription" ref="95042656"/>
<reference key="IBUIFont" ref="600433790"/>
</object>
<object class="IBUIButton" id="894322984">
<reference key="NSNextResponder" ref="538351832"/>
<int key="NSvFlags">1316</int>
<object class="NSPSMatrix" key="NSFrameMatrix"/>
<string key="NSFrame">{{20, 174}, {280, 44}}</string>
<reference key="NSSuperview" ref="538351832"/>
<reference key="NSWindow"/>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<reference key="IBUINormalTitleColor" ref="862019999"/>
<reference key="IBUIHighlightedTitleColor" ref="34193676"/>
<string key="IBUINormalTitle">Textfield with validation example</string>
<reference key="IBUINormalTitleShadowColor" ref="823323164"/>
<reference key="IBUIFontDescription" ref="95042656"/>
<reference key="IBUIFont" ref="600433790"/>
Expand All @@ -125,7 +144,6 @@
<string key="NSFrame">{{20, 293}, {280, 45}}</string>
<reference key="NSSuperview" ref="538351832"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
Expand All @@ -144,18 +162,19 @@
<int key="IBUITextAlignment">1</int>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">1</int>
<int key="weightCategory">0</int>
<double key="pointSize">17</double>
</object>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica</string>
<string key="NSName">HelveticaNeue</string>
<double key="NSSize">17</double>
<int key="NSfFlags">16</int>
</object>
<double key="preferredMaxLayoutWidth">280</double>
</object>
</array>
<object class="NSPSMatrix" key="NSFrameMatrix"/>
<string key="NSFrameSize">{320, 460}</string>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1042329230"/>
Expand All @@ -166,13 +185,17 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedSizeMetrics" key="IBUISimulatedDestinationMetrics">
<string key="IBUISimulatedSizeMetricsClass">IBUISimulatedFreeformSizeMetricsSentinel</string>
<string key="IBUIDisplayName">Freeform</string>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIResizesToFullScreen">YES</bool>
</object>
</array>
<object class="IBObjectContainer" key="IBDocument.Objects">
<bool key="usesAutoincrementingIDs">NO</bool>
<array class="NSMutableArray" key="connectionRecords">
<array key="connectionRecords">
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">delegate</string>
Expand Down Expand Up @@ -224,6 +247,15 @@
</object>
<string key="id">21</string>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">showAlert4WithTextField</string>
<reference key="source" ref="894322984"/>
<reference key="destination" ref="214709478"/>
<int key="IBEventType">7</int>
</object>
<string key="id">6UZ-Mw-lch</string>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
Expand Down Expand Up @@ -257,6 +289,7 @@
<reference ref="772694246"/>
<reference ref="688083443"/>
<reference ref="841852568"/>
<reference ref="894322984"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand All @@ -280,6 +313,11 @@
<reference key="object" ref="841852568"/>
<reference key="parent" ref="538351832"/>
</object>
<object class="IBObjectRecord">
<string key="id">7jn-vQ-IYZ</string>
<reference key="object" ref="894322984"/>
<reference key="parent" ref="538351832"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -301,12 +339,16 @@
<string key="19.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<reference key="19.IBUserGuides" ref="0"/>
<boolean value="NO" key="19.showNotes"/>
<reference key="2.IBNSViewMetadataGestureRecognizers" ref="0"/>
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<reference key="2.IBUserGuides" ref="0"/>
<boolean value="NO" key="2.showNotes"/>
<string key="3.CustomClassName">OHAlertsExampleAppDelegate</string>
<string key="3.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<boolean value="NO" key="3.showNotes"/>
<string key="7jn-vQ-IYZ.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<reference key="7jn-vQ-IYZ.IBUserGuides" ref="0"/>
<boolean value="NO" key="7jn-vQ-IYZ.showNotes"/>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
Expand Down Expand Up @@ -353,23 +395,140 @@
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/OHAlertsExampleAppDelegate.h</string>
<string key="minorKey">../OHAlertsExampleAppDelegate.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">OHAlertsExampleAppDelegate</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="showAlert1">id</string>
<string key="showAlert2">id</string>
<string key="showAlert3">id</string>
<string key="showAlert4WithTextField">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="showAlert1">
<string key="name">showAlert1</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="showAlert2">
<string key="name">showAlert2</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="showAlert3">
<string key="name">showAlert3</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="showAlert4WithTextField">
<string key="name">showAlert4WithTextField</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">../OHAlertsExampleAppDelegate.m</string>
</object>
</object>
</array>
<array class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
<object class="IBPartialClassDescription">
<string key="className">UIApplication</string>
<string key="superclassName">UIResponder</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIApplication.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIButton</string>
<string key="superclassName">UIControl</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIButton.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIControl</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIControl.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIGestureRecognizer</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIGestureRecognizer.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UILabel</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UILabel.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIResponder</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIResponder.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UISearchBar</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UISearchBar.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UISearchDisplayController</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UISearchDisplayController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIView</string>
<string key="superclassName">UIResponder</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIViewController</string>
<string key="superclassName">UIResponder</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIWindow</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIWindow.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<real value="1552" key="NS.object.0"/>
</object>
<bool key="IBDocument.previouslyAttemptedUpgradeToXcode5">NO</bool>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<integer value="4600" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">2083</string>
</data>
</archive>
1 change: 1 addition & 0 deletions Example/OHAlertsExampleAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-(IBAction)showAlert1;
-(IBAction)showAlert2;
-(IBAction)showAlert3;
-(IBAction)showAlert4WithTextField;

@end

13 changes: 13 additions & 0 deletions Example/OHAlertsExampleAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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: -
Expand Down
3 changes: 3 additions & 0 deletions OHAlertView/OHAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/////////////////////////////////////////////////////////////////////////////

Expand Down
10 changes: 10 additions & 0 deletions OHAlertView/OHAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5808938

Please sign in to comment.