Skip to content

Commit

Permalink
Major fixes to QD
Browse files Browse the repository at this point in the history
all elements now contain a weak link to the view controller
binding is by default shallow now; there's a new property called shallowBind on QElements that can bypass that
Several bug fixes
  • Loading branch information
escoz committed Feb 22, 2014
1 parent b22fd98 commit ef47633
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 86 deletions.
9 changes: 8 additions & 1 deletion QDateInlineTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,18 @@ - (void)prepareForElement:(QDateTimeInlineElement *)element inTableView:(QuickDi

self.textLabel.text = element.title;
self.detailTextLabel.text = value;
[self applyAppearanceForElement:element];;

[self applyAppearanceForElement:element];
}

- (void)applyAppearanceForElement:(QElement *)element
{
[super applyAppearanceForElement:element];

self.detailTextLabel.textColor = element.enabled ? element.appearance.entryTextColorEnabled : element.appearance.entryTextColorDisabled;
}


- (BOOL)isEditing
{
return _presentingPicker;
Expand Down
2 changes: 1 addition & 1 deletion extras/QMailElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr


- (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)path {
[self handleElementSelected:controller];
[self handleAction:controller];

if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
Expand Down
2 changes: 1 addition & 1 deletion extras/QWebElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr


- (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)path {
[self handleElementSelected:controller];
[self handleAction:controller];
if (_html) {
QWebViewController *webController = [[QWebViewController alloc] initWithHTML:_html];
webController.title = self.title;
Expand Down
2 changes: 2 additions & 0 deletions quickdialog/QAppearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
@property(nonatomic, strong) UIColor *sectionTitleShadowColor;
@property(nonatomic) BOOL toolbarTranslucent;
@property(nonatomic) CGFloat cellBorderWidth;
@property(nonatomic) NSNumber * defaultHeightForHeader;
@property(nonatomic) NSNumber * defaultHeightForFooter;

@property(nonatomic) UIBarStyle toolbarStyle;

Expand Down
4 changes: 4 additions & 0 deletions quickdialog/QAppearance.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ - (UIView *)buildFooterForSection:(QSection *)section andTableView:(QuickDialogT
- (CGFloat)heightForHeaderInSection:(QSection *)section andTableView:(QuickDialogTableView *)tableView andIndex:(NSInteger)index {
if (section.headerView!=nil)
return section.headerView.frame.size.height;
if (self.defaultHeightForHeader!=nil)
return self.defaultHeightForHeader.floatValue;
return UITableViewAutomaticDimension;
}

- (CGFloat)heightForFooterInSection:(QSection *)section andTableView:(QuickDialogTableView *)tableView andIndex:(NSInteger)index {
if (section.footerView!=nil)
return section.footerView.frame.size.height;
if (self.defaultHeightForFooter!=nil)
return self.defaultHeightForFooter.floatValue;

return UITableViewAutomaticDimension;
}
Expand Down
2 changes: 1 addition & 1 deletion quickdialog/QBindingEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

- (void)bindObject:(id)section toData:(id)data;

- (void)bindObject:(id)object toData:(id)data andBindingString:(id)string;
- (void)bindObject:(id)object toData:(id)data withString:(id)string;

- (void)bindSection:(QSection *)section toCollection:(NSArray *)items;

Expand Down
4 changes: 2 additions & 2 deletions quickdialog/QBindingEvaluator.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ - (void)bindObject:(id)object toData:(id)data {
return;

NSString *string = [object bind];
[self bindObject:object toData:data andBindingString:string];
[self bindObject:object toData:data withString:string];
}

- (void)bindObject:(id)object toData:(id)data andBindingString:string {
- (void)bindObject:(id)object toData:(id)data withString:string {

if ([QBindingEvaluator stringIsEmpty:string])
return;
Expand Down
18 changes: 5 additions & 13 deletions quickdialog/QBooleanElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#import "QuickDialogController.h"

@implementation QBooleanElement {
__unsafe_unretained QuickDialogController *_controller;
}
@synthesize onImage = _onImage;
@synthesize offImage = _offImage;
Expand Down Expand Up @@ -57,7 +56,7 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr
UITableViewCell *cell = [super getCellForTableView:tableView controller:controller];
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 = self.boolValue;
Expand Down Expand Up @@ -91,20 +90,13 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro

if (self.controllerAction==nil)
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self handleElementSelected:controller];
[self handleAction];
}

- (void)buttonPressed:(UIButton *)boolButton {
self.boolValue = !boolButton.selected;
boolButton.selected = _boolValue;
if (_controller!=nil && self.controllerAccessoryAction!=nil) {
SEL selector = NSSelectorFromString(self.controllerAccessoryAction);
if ([_controller respondsToSelector:selector]) {
objc_msgSend(_controller,selector, self);
} else {
NSLog(@"No method '%@' was found on controller %@", self.controllerAccessoryAction, [_controller class]);
}
}
[self performAccessoryAction];
}

-(void)setBoolValue:(BOOL)boolValue {
Expand All @@ -115,8 +107,8 @@ -(void)setBoolValue:(BOOL)boolValue {

- (void)switched:(id)boolSwitch {
self.boolValue = ((UISwitch *)boolSwitch).on;
if ((_controller != nil && self.controllerAction != nil) || _onSelected != nil) {
[self handleElementSelected:_controller];
if ((self.controller != nil && self.controllerAction != nil) || _onSelected != nil) {
[self handleAction];
}
}

Expand Down
2 changes: 1 addition & 1 deletion quickdialog/QClassicAppearance.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (UIView *)buildHeaderForSection:(QSection *)section andTableView:(QuickDialogT
containerView.backgroundColor = [UIColor clearColor];
containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(margin, 8, tableView.bounds.size.width-margin-margin, height-4)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(margin, 8, tableView.bounds.size.width-margin-margin, height -4)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label.text = section.title;
[containerView addSubview:label];
Expand Down
7 changes: 4 additions & 3 deletions quickdialog/QDateTimeInlineElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ - (QDateInlineTableViewCell *)getInlineCell:(QuickDialogTableView *)tableView
cell.selectionStyle = !self.enabled || self.showPickerInCell ? UITableViewCellSelectionStyleNone : UITableViewCellSelectionStyleBlue;
cell.imageView.image = self.image;
cell.labelingPolicy = self.labelingPolicy;

return cell;
}

Expand All @@ -120,14 +121,14 @@ - (QDateEntryTableViewCell *)getEntryCell:(QuickDialogTableView *)tableView
return cell;
}

- (void)handleElementSelected:(QuickDialogController *)controller
- (void)handleAction
{
if (self.showPickerInCell){
BOOL shouldEdit = !_cell.isEditing;

[controller.quickDialogTableView endEditingOnVisibleCells];
[((QuickDialogController *)self.controller).quickDialogTableView endEditingOnVisibleCells];
[_cell setEditing:shouldEdit];
[controller.quickDialogTableView reloadRowHeights];
[((QuickDialogController *)self.controller).quickDialogTableView reloadRowHeights];
}
}

Expand Down
5 changes: 3 additions & 2 deletions quickdialog/QDynamicDataSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ - (QDynamicDataSection *)init {
return self;
}

- (void)bindToObject:(id)data {
- (void)bindToObject:(id)data withString:(NSString *)withBindString
{

[self.elements removeAllObjects];

[super bindToObject:data];
[super bindToObject:data withString:withBindString];

if (self.elements.count>0) //elements exist
return;
Expand Down
14 changes: 11 additions & 3 deletions quickdialog/QElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@interface QElement : NSObject {

@protected
__unsafe_unretained QSection *_parentSection;
__weak QSection *_parentSection;
__weak UIViewController *_controller;
NSString *_key;
NSString *_bind;

Expand All @@ -48,14 +49,17 @@
@property(nonatomic) BOOL hidden;
@property(nonatomic,readonly) NSUInteger visibleIndex;

@property(nonatomic, assign) QSection *parentSection;
@property(nonatomic, weak) QSection *parentSection;
@property(nonatomic, weak) UIViewController *controller;

@property(nonatomic, retain) NSString *key;
@property(nonatomic, retain) id object;
@property(nonatomic, retain) NSString *bind;

@property (nonatomic) QLabelingPolicy labelingPolicy;

@property(nonatomic) BOOL shallowBind;

- (QElement *)initWithKey:(NSString *)key;

- (NSIndexPath*) getIndexPath;
Expand All @@ -64,7 +68,6 @@

-(QTableViewCell *)getOrCreateEmptyCell:(QuickDialogTableView *)tableView;

- (void)handleElementSelected:(QuickDialogController *)controller;

- (void)selectedAccessory:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)indexPath;

Expand All @@ -75,9 +78,14 @@

- (void)fetchValueIntoObject:(id)obj;

- (void)bindToObject:(id)data withString:(NSString *)string;

- (void)bindToObject:(id)obj;

- (void)fetchValueUsingBindingsIntoObject:(id)object;

- (void)handleAction;
- (void)performAccessoryAction;

- (void)bindToObject:(id)data shallow:(BOOL)shallow;
@end
53 changes: 39 additions & 14 deletions quickdialog/QElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ - (QElement *)init {
self = [super init];
if (self) {
self.enabled = YES;
self.shallowBind = YES;
}
return self;
}
Expand All @@ -51,11 +52,14 @@ - (QElement *)initWithKey:(NSString *)key {
if (self){
self.key = key;
self.enabled = YES;
self.shallowBind = YES;
}
return self;
}

- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {
_controller = controller;

QTableViewCell *cell= [self getOrCreateEmptyCell:tableView];

[cell applyAppearanceForElement:self];
Expand All @@ -73,24 +77,12 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr
- (QTableViewCell *)getOrCreateEmptyCell:(QuickDialogTableView *)tableView {
QTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"QuickformElementCell%@%@", self.key, self.class]];
if (cell == nil){
cell = [[QTableViewCell alloc] initWithReuseIdentifier:[NSString stringWithFormat:@"QuickformElementCell%@%@", self.key, self.class]];
cell = [[QTableViewCell alloc] initWithReuseIdentifier:[NSString stringWithFormat:@"QuickformElementCell%@%@", self.key, NSStringFromClass(self.class)]];
}
return cell;
}

- (void)handleElementSelected:(QuickDialogController *)controller {
if (_onSelected!= nil)
_onSelected();

if (self.controllerAction!=NULL){
SEL selector = NSSelectorFromString(self.controllerAction);
if ([controller respondsToSelector:selector]) {
objc_msgSend(controller,selector, self);
} else {
NSLog(@"No method '%@' was found on controller %@", self.controllerAction, [controller class]);
}
}
}

- (void)selectedAccessory:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)indexPath{
if (self.controllerAccessoryAction!=NULL){
Expand All @@ -104,8 +96,9 @@ - (void)selectedAccessory:(QuickDialogTableView *)tableView controller:(QuickDi
}

- (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)indexPath {
_controller = controller;
[[tableView cellForRowAtIndexPath:indexPath] becomeFirstResponder];
[self handleElementSelected:controller];
[self handleAction];
}

- (CGFloat)getRowHeightForTableView:(QuickDialogTableView *)tableView {
Expand All @@ -125,15 +118,47 @@ - (NSIndexPath*) getIndexPath
- (void)fetchValueIntoObject:(id)obj {
}

-(void)bindToObject:(id)data withString:(NSString *)string{
[[QBindingEvaluator new] bindObject:self toData:data withString:string];
}

-(void)bindToObject:(id)data {
[[QBindingEvaluator new] bindObject:self toData:data];
}


- (void)bindToObject:(id)data shallow:(BOOL)shallow
{
[[QBindingEvaluator new] bindObject:self toData:data];
}

- (void)fetchValueUsingBindingsIntoObject:(id)data {
[[QBindingEvaluator new] fetchValueFromObject:self toData:data];
}

- (void)handleAction {
if (_onSelected!= nil)
_onSelected();

if (self.controllerAction!=NULL){
SEL selector = NSSelectorFromString(self.controllerAction);
if ([_controller respondsToSelector:selector]) {
objc_msgSend(_controller,selector, self);
} else {
NSLog(@"No method '%@' was found on controller %@", self.controllerAction, [_controller class]);
}
}
}

-(void)performAccessoryAction{
if (_controller!=nil && self.controllerAccessoryAction!=nil) {
SEL selector = NSSelectorFromString(self.controllerAccessoryAction);
if ([_controller respondsToSelector:selector]) {
objc_msgSend(_controller,selector, self);
} else {
NSLog(@"No method '%@' was found on controller %@", self.controllerAccessoryAction, [_controller class]);
}
}
}

@end
10 changes: 4 additions & 6 deletions quickdialog/QEntryElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

#import "QEntryElement.h"
#import "QuickDialog.h"
@implementation QEntryElement {
__unsafe_unretained QuickDialogController *_controller;
}
@implementation QEntryElement

@synthesize textValue = _textValue;
@synthesize placeholder = _placeholder;
Expand Down Expand Up @@ -55,13 +53,14 @@ - (QEntryElement *)initWithTitle:(NSString *)title Value:(NSString *)value Place

- (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller {

self.controller = controller;

QEntryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QuickformEntryElement"];
if (cell==nil){
cell = [[QEntryTableViewCell alloc] init];
}

[cell applyAppearanceForElement:self];
_controller = controller;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textField.enabled = self.enabled;
cell.textField.userInteractionEnabled = self.enabled;
Expand All @@ -78,7 +77,7 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro

- (void) fieldDidEndEditing
{
[self handleElementSelected:_controller];
[self handleAction];
}

- (void)fetchValueIntoObject:(id)obj {
Expand Down Expand Up @@ -111,7 +110,6 @@ - (void)handleEditingChanged:(QEntryTableViewCell *)cell
@synthesize enablesReturnKeyAutomatically = _enablesReturnKeyAutomatically;
@synthesize secureTextEntry = _secureTextEntry;
@synthesize clearsOnBeginEditing = _clearsOnBeginEditing;
@synthesize accessoryType = _accessoryType;
@synthesize customDateFormat = _customDateFormat;


Expand Down
Loading

0 comments on commit ef47633

Please sign in to comment.