Skip to content

Commit

Permalink
Added a QPresentationMode to root elements that make them display eit…
Browse files Browse the repository at this point in the history
…her in a popover or a popover with a navigationcontroller automaticaly. This is currently being used by the QMultilineElement and QRadioElement when running on iPad
  • Loading branch information
escoz committed Nov 12, 2012
1 parent c5de6ea commit f482fcd
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 11 deletions.
12 changes: 11 additions & 1 deletion quickdialog/QMultilineElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ @implementation QMultilineElement
@synthesize delegate = _delegate;


- (QEntryElement *)init {
self = [super init];
if (self) {
self.presentationMode = QPresentationModePopover;
}

return self;
}

- (QMultilineElement *)initWithTitle:(NSString *)title value:(NSString *)text
{
if ((self = [super initWithTitle:title Value:nil])) {
self.textValue = text;
self.presentationMode = QPresentationModePopover;
}
return self;
}
Expand Down Expand Up @@ -54,7 +64,7 @@ - (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogContro
weakSelf.textValue = textController.textView.text;
[[tableView cellForElement:weakSelf] setNeedsDisplay];
};
[controller displayViewController:textController];
[controller displayViewControllerInPopover:textController withNavigation:NO];
}

- (void)fetchValueIntoObject:(id)obj
Expand Down
1 change: 1 addition & 0 deletions quickdialog/QRadioElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation QRadioElement {

- (void)createElements {
_sections = nil;
self.presentationMode = QPresentationModeNavigationInPopover;
_internalRadioItemsSection = [[QSection alloc] init];
_parentSection = _internalRadioItemsSection;

Expand Down
11 changes: 10 additions & 1 deletion quickdialog/QRootElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
#import "QElement.h"
#import "QSection.h"


typedef enum {
QPresentationModeNormal = 0,
QPresentationModePopover,
QPresentationModeNavigationInPopover
} QPresentationMode;

@interface QRootElement : QElement {

@protected
Expand All @@ -34,6 +41,8 @@
@property(nonatomic, copy) void (^onValueChanged)(void);

@property(nonatomic, copy) NSString *emptyMessage;
@property(nonatomic) QPresentationMode presentationMode;


- (QRootElement *)init;

Expand All @@ -48,4 +57,4 @@

- (QSection *)sectionWithKey:(NSString *)key;
- (QElement *)elementWithKey:(NSString *)string;
@end
@end
5 changes: 4 additions & 1 deletion quickdialog/QRootElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@implementation QRootElement {
@private
NSDictionary *_sectionTemplate;
QPresentationMode _presentationMode;
void (^_onValueChanged)();
}

Expand All @@ -28,11 +29,13 @@ @implementation QRootElement {
@synthesize sectionTemplate = _sectionTemplate;
@synthesize emptyMessage = _emptyMessage;
@synthesize onValueChanged = _onValueChanged;
@synthesize presentationMode = _presentationMode;


- (QRootElement *)init {
self = [super init];
return self;

}
- (void)addSection:(QSection *)section {
if (_sections==nil)
Expand Down Expand Up @@ -124,4 +127,4 @@ - (QElement *)elementWithKey:(NSString *)elementKey {
}
return nil;
}
@end
@end
9 changes: 7 additions & 2 deletions quickdialog/QuickDialogController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#import "QuickDialogTableView.h"

@interface QuickDialogController : UIViewController {
@interface QuickDialogController : UIViewController <UIPopoverControllerDelegate> {

@private
QRootElement *_root;
Expand All @@ -32,6 +32,8 @@
@property(nonatomic) BOOL resizeWhenKeyboardPresented;


@property(nonatomic, strong) UIPopoverController *popoverBeingPresented;

- (void)loadView;

- (QuickDialogController *)initWithRoot:(QRootElement *)rootElement;
Expand All @@ -40,10 +42,13 @@

- (void)displayViewControllerForRoot:(QRootElement *)element;

- (void)displayViewControllerInPopover:(QuickDialogController *)newController withNavigation:(BOOL)navigation;


- (QuickDialogController *)controllerForRoot:(QRootElement *)root;

+ (QuickDialogController *)controllerForRoot:(QRootElement *)root;

+ (UINavigationController *)controllerWithNavigationForRoot:(QRootElement *)root;

@end
@end
49 changes: 46 additions & 3 deletions quickdialog/QuickDialogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ @implementation QuickDialogController {
BOOL _keyboardVisible;
BOOL _viewOnScreen;
BOOL _resizeWhenKeyboardPresented;
UIPopoverController *_popoverForChildRoot;
}

@synthesize root = _root;
@synthesize willDisappearCallback = _willDisappearCallback;
@synthesize quickDialogTableView = _quickDialogTableView;
@synthesize resizeWhenKeyboardPresented = _resizeWhenKeyboardPresented;
@synthesize popoverBeingPresented = _popoverBeingPresented;


+ (QuickDialogController *)buildControllerWithClass:(Class)controllerClass root:(QRootElement *)root {
Expand Down Expand Up @@ -115,7 +117,14 @@ - (void)viewWillDisappear:(BOOL)animated {
}

- (void)popToPreviousRootElementOnMainThread {
if (self.navigationController!=nil){

if ([self popoverBeingPresented]!=nil){
[self.popoverBeingPresented dismissPopoverAnimated:YES];
if (self.popoverBeingPresented.delegate!=nil){
[self.popoverBeingPresented.delegate popoverControllerDidDismissPopover:self.popoverBeingPresented];
}
}
else if (self.navigationController!=nil){
[self.navigationController popViewControllerAnimated:YES];
} else {
[self dismissModalViewControllerAnimated:YES];
Expand All @@ -136,7 +145,41 @@ - (void)displayViewController:(UIViewController *)newController {

- (void)displayViewControllerForRoot:(QRootElement *)root {
QuickDialogController *newController = [self controllerForRoot: root];
[self displayViewController:newController];

if (root.presentationMode==QPresentationModeNormal) {
[self displayViewController:newController];

} else if (root.presentationMode == QPresentationModePopover || root.presentationMode == QPresentationModeNavigationInPopover) {
[self displayViewControllerInPopover:newController withNavigation:root.presentationMode==QPresentationModeNavigationInPopover];
}
}

- (void)displayViewControllerInPopover:(UIViewController *)newController withNavigation:(BOOL)navigation {

if ([UIDevice currentDevice].userInterfaceIdiom!=UIUserInterfaceIdiomPad){
[self displayViewController:newController];
return;
}

UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:
navigation ? [[UINavigationController alloc] initWithRootViewController :newController] : newController
];
popoverController.popoverContentSize = CGSizeMake(320, 360);
if ([newController respondsToSelector:@selector(setPopoverBeingPresented:)]) {
[newController performSelector:@selector(setPopoverBeingPresented:) withObject:popoverController];
} else {
_popoverForChildRoot = popoverController;
}
popoverController.delegate = self;

CGRect position = [self.quickDialogTableView rectForRowAtIndexPath:self.quickDialogTableView.indexPathForSelectedRow];
[popoverController presentPopoverFromRect:position inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[self.quickDialogTableView reloadData];
_popoverForChildRoot = nil;

}


Expand Down Expand Up @@ -193,4 +236,4 @@ - (void)dealloc {
}


@end
@end
5 changes: 2 additions & 3 deletions sample/SampleDataBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,8 @@ + (QRootElement *)createEntryRoot {
multiline.title = @"Multiline entry";
[multilineSection addElement:multiline];


[root addSection:traitsSection];
[root addSection:multilineSection];
[root addSection:traitsSection];

return root;
}
Expand Down Expand Up @@ -698,4 +697,4 @@ + (QRootElement *)create {

return root;
}
@end
@end

0 comments on commit f482fcd

Please sign in to comment.