Skip to content
Browse files

QBoolElement now executes the controllerAction when the value changes…

…. Follow up to Issue #46
  • Loading branch information...
1 parent cd38229 commit acbd769b830ff6b8fd3a0216273f27025861cb81 @escoz escoz committed Jan 23, 2012
Showing with 11 additions and 6 deletions.
  1. +10 −6 quickdialog/QBooleanElement.m
  2. +1 −0 sample/SampleDataBuilder.m
View
16 quickdialog/QBooleanElement.m
@@ -12,8 +12,9 @@
// permissions and limitations under the License.
//
-@implementation QBooleanElement
-
+@implementation QBooleanElement {
+ __unsafe_unretained QuickDialogController *_controller;
+}
@synthesize onImage = _onImage;
@synthesize offImage = _offImage;
@synthesize boolValue = _boolValue;
@@ -34,9 +35,9 @@ - (QBooleanElement *)initWithTitle:(NSString *)title BoolValue:(BOOL)value {
- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
UITableViewCell *cell = [super getCellForTableView:tableView controller:controller];
- cell.accessoryType = self.sections!= nil || self.controllerAction!=nil ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
- cell.selectionStyle = self.sections!= nil || self.controllerAction!=nil ? UITableViewCellSelectionStyleBlue: UITableViewCellSelectionStyleNone;
-
+ cell.accessoryType = self.sections!= nil ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
+ cell.selectionStyle = self.sections!= nil ? UITableViewCellSelectionStyleBlue: UITableViewCellSelectionStyleNone;
+ _controller = controller;
if ((_onImage==nil) && (_offImage==nil)) {
UISwitch *boolSwitch = [[UISwitch alloc] init];
boolSwitch.on = _boolValue;
@@ -60,12 +61,15 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro
((UIImageView *)cell.accessoryView).image = _boolValue ? _onImage : _offImage;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
- [self handleElementSelected:controller];
+ if (self.sections!=nil)
+ [self handleElementSelected:controller];
}
- (void)switched:(id)boolSwitch {
_boolValue = ((UISwitch *)boolSwitch).on;
+ if (_controller!=nil && self.controllerAction!=nil)
+ [self handleElementSelected:_controller];
}
- (void)fetchValueIntoObject:(id)obj {
View
1 sample/SampleDataBuilder.m
@@ -152,6 +152,7 @@ + (QElement *)createSampleControls {
radioElement.key = @"radio1";
QBooleanElement *boolElement = [[QBooleanElement alloc] initWithTitle:@"Boolean Element" BoolValue:YES];
+ boolElement.controllerAction = @"exampleAction:";
boolElement.key = @"bool1";
QEntryElement *entryElement = [[QEntryElement alloc] initWithTitle:@"Entry Element" Value:nil Placeholder:@"type here"];

0 comments on commit acbd769

Please sign in to comment.
Something went wrong with that request. Please try again.