Skip to content

Commit

Permalink
Merge pull request #4536 from vishalduggal/timob-14292-31X
Browse files Browse the repository at this point in the history
[TIMOB-14292] (3_1_X) Avoid race condition on view detach
  • Loading branch information
srahim committed Aug 6, 2013
2 parents 6e75100 + 8c20992 commit 78d4077
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions iphone/Classes/TiUITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@
NSInteger frameChanges;
TiViewProxy* headerViewProxy;
TiViewProxy* footerViewProxy;
BOOL viewWillDetach;
}

@property (nonatomic, assign) BOOL viewWillDetach;

#pragma mark Framework
-(CGFloat)tableRowHeight:(CGFloat)height;
-(NSInteger)indexForRow:(TiUITableViewRowProxy*)row;
Expand Down
16 changes: 14 additions & 2 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ -(void) setSelectedBackgroundGradient_:(TiGradient *)newGradient

@implementation TiUITableView
#pragma mark Internal
@synthesize searchString;
@synthesize searchString, viewWillDetach;

-(id)init
{
Expand Down Expand Up @@ -1260,7 +1260,11 @@ -(CGFloat)contentHeightForWidth:(CGFloat)suggestedWidth

-(void)hideSearchScreen:(id)sender
{
// check to make sure we're not in the middle of a layout, in which case we
if (viewWillDetach) {
return;
}

// check to make sure we're not in the middle of a layout, in which case we
// want to try later or we'll get weird drawing animation issues
if (tableview.frame.size.width==0)
{
Expand Down Expand Up @@ -1290,6 +1294,10 @@ -(void)hideSearchScreen:(id)sender
// because of where the hide might be triggered from.


if (viewWillDetach) {
return;
}
searchActivated = NO;
NSArray* visibleRows = [tableview indexPathsForVisibleRows];
[tableview reloadRowsAtIndexPaths:visibleRows withRowAnimation:UITableViewRowAnimationNone];

Expand Down Expand Up @@ -2428,6 +2436,10 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
if (viewWillDetach) {
return;
}

animateHide = YES;
[self performSelector:@selector(hideSearchScreen:) withObject:nil afterDelay:0.2];
}
Expand Down
4 changes: 3 additions & 1 deletion iphone/Classes/TiUITableViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ -(TiUITableView*)tableView

-(void)viewWillDetach
{
((TiUITableView*)[self view]).viewWillDetach = YES;
for (TiUITableViewSectionProxy* section in sections) {
for (TiUITableViewRowProxy* row in [section rows]) {
[row detachView];
Expand All @@ -77,7 +78,8 @@ -(void)viewWillDetach

-(void)viewDidAttach
{
TiUITableView * ourView = (TiUITableView *)[self view];
TiUITableView * ourView = (TiUITableView *)[self view];
ourView.viewWillDetach = NO;
for (TiUITableViewSectionProxy* section in sections) {
[section setTable:ourView];
}
Expand Down

0 comments on commit 78d4077

Please sign in to comment.