I have to render dynamic form in iPhone application using tableview. This form may have multiple UI controls as button,textfield,lable, picker,date picker .
I got one sample code for iPad which is able to render the dynamic form,but this sample code is using UIPopoverController, which is not supported by iPhone application.
So I am looking for some sample code which should work in iPhone.
Below is the code which shows combo box on clicking the button in dynamic form. I need the code which should show picker with list items.
sample code: https://github.com/ecrichlow/iPad-Dynamic-Table-Cells
- (IBAction)buttonPressed:(id)sender
{
[delegate rowItemWasSelected:self];
if (self.itemControlType == ControlTypeToggleButton)
{
...
}
else if (self.itemControlType == ControlTypePopup)
{
...
}
else if (self.itemControlType == ControlTypeCombo)
{
UITableViewController *popoverTable = [[[UITableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, DEFAULT_POPOVER_WIDTH, DEFAULT_TOOLBAR_HEIGHT)] autorelease];
UIView *containerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, DEFAULT_POPOVER_WIDTH, ([self.controlSelections count] * popoverTable.tableView.rowHeight) + DEFAULT_TOOLBAR_HEIGHT)] autorelease];
UIViewController *containerViewController = [[[UIViewController alloc] init] autorelease];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:containerViewController];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(DEFAULT_COMBO_TEXTFIELD_MARGIN, (DEFAULT_TOOLBAR_HEIGHT - DEFAULT_COMBO_TEXTFIELD_HEIGHT) / 2, DEFAULT_POPOVER_WIDTH - (DEFAULT_COMBO_TEXTFIELD_MARGIN * 2), DEFAULT_COMBO_TEXTFIELD_HEIGHT)];
textField.delegate = self;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.font = [UIFont systemFontOfSize:DEFAULT_COMBO_FONT_SIZE];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[textField addTarget:self action:@selector(fieldTextDidUpdate:) forControlEvents:UIControlEventEditingDidEnd];
containerViewController.view = containerView;
popoverTable.tableView.dataSource = self;
popoverTable.tableView.delegate = self;
popoverTable.tableView.frame = CGRectMake(0, DEFAULT_TOOLBAR_HEIGHT, DEFAULT_POPOVER_WIDTH, [self.controlSelections count] * popoverTable.tableView.rowHeight);
popoverController.popoverContentSize = CGSizeMake(DEFAULT_POPOVER_WIDTH, ([self.controlSelections count] * popoverTable.tableView.rowHeight) + DEFAULT_TOOLBAR_HEIGHT);
popoverController.delegate = self;
[toolbar addSubview:textField];
[containerView addSubview:toolbar];
[containerView addSubview:popoverTable.tableView];
optionPopoverController = popoverController;
[popoverController presentPopoverFromRect:control.frame inView:control.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
// If there's currently an object that's first responder, make it resign that status
for (UIView *subview in self.control.superview.subviews)
{
if ([subview isKindOfClass:[UITextField class]])
{
if ([subview isFirstResponder])
{
[subview resignFirstResponder];
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
}
}
}
[textField becomeFirstResponder];
}
else if (self.itemControlType == ControlTypeButton)
{
// Don't need to do anything here. Caller passed in target and action. But in order to trigger delegate rowItemWasSelected this control type was added here.
}
}
You can modify the sample code iPad-Dynamic-Table-Cells for rendering dynamic form in iPhone along with with popover display also
Add the below 6 files of project available on git-hub https://github.com/50pixels/FPPopover to your iPad-Dynamic-Table-Cells sample code
FPPopoverController.h/.m, FPPopoverView.h/m, and FPTouchView.h/.m
Now modify the FPTouchView.m, EditableTableDataRowItem.h and EditableTableDataRowItem.m as below
//In EditableTableDataRowItem.m
//In FPTouchView.m file
//Need to handle this method