Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for block based right bar button items #625

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions quickdialog/QRootElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ typedef enum {
}

@property(nonatomic, retain) NSString *title;
@property(nonatomic, retain) NSString *rightBarButtonTitle;
@property(nonatomic, copy) dispatch_block_t rightBarButtonAction;

@property(nonatomic, strong) NSMutableArray *sections;
@property(nonatomic, strong) NSDictionary *sectionTemplate;
@property(assign) BOOL grouped;
Expand Down
12 changes: 11 additions & 1 deletion quickdialog/QuickDialogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,25 @@ - (void)setRoot:(QRootElement *)root {
self.quickDialogTableView.root = root;
self.title = _root.title;
self.navigationItem.title = _root.title;
if (root.rightBarButtonTitle) {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:_root.rightBarButtonTitle style:UIBarButtonItemStylePlain target:self action:@selector(didSelectRightBarButtonItem)];
}
}
-(void) didSelectRightBarButtonItem{
if (_root.rightBarButtonAction) {
_root.rightBarButtonAction();
}
}

- (void)viewWillAppear:(BOOL)animated {
_viewOnScreen = YES;
[self.quickDialogTableView deselectRows];
[super viewWillAppear:animated];
if (_root!=nil) {
self.title = _root.title;
self.navigationItem.title = _root.title;
if (_root.rightBarButtonTitle) {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:_root.rightBarButtonTitle style:UIBarButtonItemStylePlain target:self action:@selector(didSelectRightBarButtonItem)];
}
if (_root.preselectedElementIndex !=nil)
[self.quickDialogTableView scrollToRowAtIndexPath:_root.preselectedElementIndex atScrollPosition:UITableViewScrollPositionTop animated:NO];

Expand Down
5 changes: 5 additions & 0 deletions sample/SampleDataBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ + (QRootElement *)createSampleFormRoot {
QSection *subsection = [[QSection alloc] initWithTitle:@"SubSection"];
subForm.grouped = YES;
subForm.title = @"Subform";
subForm.rightBarButtonTitle = @"Click Here";
subForm.rightBarButtonAction = ^{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Example Right bar button action" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
};
subForm.controllerName = @"ExampleViewController";

[subsection addElement:[[QLabelElement alloc] initWithTitle:@"Some title" Value:@"Some value"]];
Expand Down