Skip to content

Commit

Permalink
added reloadData on table alert that will intelligently resize the alert
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj committed Mar 20, 2012
1 parent 4ad5677 commit e6390f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions BlockAlertsDemo/BlockAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ - (void)show
modalBackground.image = background;

modalBackground.contentMode = UIViewContentModeScaleToFill;
modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[_view insertSubview:modalBackground atIndex:0];
[modalBackground release];

Expand Down
2 changes: 2 additions & 0 deletions BlockAlertsDemo/BlockTableAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ typedef enum {

- (id)initWithTitle:(NSString *)title message:(NSString *)message;

- (void)reloadData;

+ (BlockTableAlertView *)tableAlertWithTitle:(NSString *)title message:(NSString *)message;

@end
23 changes: 23 additions & 0 deletions BlockAlertsDemo/BlockTableAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim
[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}

- (void)reloadData {
CGFloat oldTableHeight = _tableView.frame.size.height;

[self.tableView reloadData];

CGFloat newTableHeight = kDefaultRowHeight * MIN(self.numberOfRowsInTableAlert(self), kNumMaximumVisibleRowsInTableView);

if (newTableHeight != oldTableHeight) {
CGFloat diff = newTableHeight - oldTableHeight;
[UIView animateWithDuration:0.3 animations:^{
[self.view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *v = obj;
if (v.frame.origin.y >= _tableView.frame.origin.y + _tableView.frame.size.height)
v.frame = CGRectMake(v.frame.origin.x, v.frame.origin.y + diff, v.frame.size.width, v.frame.size.height);
}];

_tableView.frame = CGRectMake(_tableView.frame.origin.x, _tableView.frame.origin.y, _tableView.frame.size.width, newTableHeight);
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height + diff);
}];

}
}

- (void)show {
if (!_shown)
[self setupDisplay];
Expand Down

0 comments on commit e6390f3

Please sign in to comment.