Skip to content

Commit

Permalink
Trim whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Guo committed Apr 10, 2014
1 parent 6078152 commit 60205fc
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions BZGFormViewController/BZGFormViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ - (void)loadView
}
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = BZG_TABLEVIEW_BACKGROUND_COLOR;

UIView *contentView = [[UIView alloc] initWithFrame:CGRectZero];
contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[contentView addSubview:self.tableView];

self.view = contentView;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
Expand Down Expand Up @@ -97,27 +97,27 @@ - (BZGInfoCell *)infoCellBelowFormCell:(BZGTextFieldCell *)cell
NSUInteger cellIndex = [self.formCells indexOfObject:cell];
if (cellIndex == NSNotFound) return nil;
if (cellIndex + 1 >= self.formCells.count) return nil;

UITableViewCell *cellBelow = self.formCells[cellIndex + 1];
if ([cellBelow isKindOfClass:[BZGInfoCell class]]) {
return (BZGInfoCell *)cellBelow;
}

return nil;
}

- (void)showInfoCellBelowFormCell:(BZGTextFieldCell *)cell
{
NSUInteger cellIndex = [self.formCells indexOfObject:cell];
if (cellIndex == NSNotFound) return;

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:cellIndex+1
inSection:self.formSection];

// if an info cell is already showing, do nothing
BZGInfoCell *infoCell = [self infoCellBelowFormCell:cell];
if (infoCell) return;

// otherwise, add the cell's info cell to the table view
[self.formCells insertObject:cell.infoCell atIndex:cellIndex+1];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
Expand All @@ -128,11 +128,11 @@ - (void)removeInfoCellBelowFormCell:(BZGTextFieldCell *)cell
{
NSUInteger cellIndex = [self.formCells indexOfObject:cell];
if (cellIndex == NSNotFound) return;

// if no info cell is showing, do nothing
BZGInfoCell *infoCell = [self infoCellBelowFormCell:cell];
if (!infoCell) return;

// otherwise, remove it
[self.formCells removeObjectAtIndex:cellIndex+1];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:cellIndex+1
Expand Down Expand Up @@ -169,7 +169,7 @@ - (BZGTextFieldCell *)nextFormCell:(BZGTextFieldCell *)cell
{
NSUInteger cellIndex = [self.formCells indexOfObject:cell];
if (cellIndex == NSNotFound) return nil;

for (NSUInteger i = cellIndex + 1; i < self.formCells.count; ++i) {
UITableViewCell *cell = self.formCells[i];
if ([cell isKindOfClass:[BZGTextFieldCell class]]) {
Expand All @@ -183,7 +183,7 @@ - (BZGTextFieldCell *)previousFormCell:(BZGTextFieldCell *)cell
{
NSUInteger cellIndex = [self.formCells indexOfObject:cell];
if (cellIndex == NSNotFound || cellIndex == 0) return nil;

for (NSInteger i = cellIndex - 1; i >= 0; --i) {
UITableViewCell *cell = self.formCells[i];
if ([cell isKindOfClass:[BZGTextFieldCell class]]) {
Expand Down Expand Up @@ -231,7 +231,7 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField
if (cell.didBeginEditingBlock) {
cell.didBeginEditingBlock(cell, textField.text);
}

NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
if (self.showsKeyboardControl) {
Expand All @@ -246,12 +246,12 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
if (!cell) {
return YES;
}

NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (cell.shouldChangeTextBlock) {
shouldChange = cell.shouldChangeTextBlock(cell, newText);
}

[self updateInfoCellBelowFormCell:cell];
return shouldChange;
}
Expand All @@ -265,7 +265,7 @@ - (void)textFieldDidEndEditing:(UITextField *)textField
if (cell.didEndEditingBlock) {
cell.didEndEditingBlock(cell, textField.text);
}

[self updateInfoCellBelowFormCell:cell];
}

Expand All @@ -276,19 +276,19 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField
if (!cell) {
return YES;
}

if (cell.shouldReturnBlock) {
shouldReturn = cell.shouldReturnBlock(cell, textField.text);
}

BZGTextFieldCell *nextCell = [self nextFormCell:cell];
if (!nextCell) {
[cell.textField resignFirstResponder];
}
else {
[nextCell.textField becomeFirstResponder];
}

[self updateInfoCellBelowFormCell:cell];
return shouldReturn;
}
Expand All @@ -312,14 +312,14 @@ - (void)formCell:(BZGFormCell *)formCell didChangeValidationState:(BZGValidation

- (void)keyboardWillShow:(NSNotification *)notification {
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets;
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize.height), 0.0);
} else {
contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize.width), 0.0);
}

self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
}
Expand Down

0 comments on commit 60205fc

Please sign in to comment.