Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[TIMOB-11760] Make TableViewRow reuse conditional #3424

Merged
merged 1 commit into from

2 participants

@mstepanov

TIMOB-11760

Test instructions in JIRA.

@vishalduggal
Collaborator

Code Reviewed. ACCEPTED

@vishalduggal
Collaborator

FR Passed. Also fixes TIMOB-11715. ACCEPTED

@vishalduggal vishalduggal merged commit 30d1747 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @mstepanov
This page is out of date. Refresh to see the latest.
View
1  iphone/Classes/TiUITableViewRowProxy.h
@@ -43,6 +43,7 @@ typedef enum
#pragma mark Public APIs
@property(nonatomic,readonly) NSString *tableClass;
+@property(nonatomic, readwrite) BOOL reusable;
#pragma mark Framework
View
119 iphone/Classes/TiUITableViewRowProxy.m
@@ -255,6 +255,7 @@ - (void) dealloc
@implementation TiUITableViewRowProxy
@synthesize tableClass, table, section, row, callbackCell;
+@synthesize reusable;
-(NSString *)className
{
@@ -649,7 +650,7 @@ -(UIView *)parentViewForChild:(TiViewProxy *)child
-(BOOL)viewAttached
{
- return rowContainerView != nil;
+ return callbackCell != nil;
}
-(BOOL)canHaveControllerParent
@@ -679,6 +680,10 @@ -(UIView*)view
- (void)prepareTableRowForReuse
{
+ if (!self.reusable) {
+ [rowContainerView removeFromSuperview];
+ return;
+ }
if (![self.tableClass isEqualToString:defaultRowTableClass]) {
return;
}
@@ -691,6 +696,18 @@ - (void)prepareTableRowForReuse
}
}
+- (void)didReceiveMemoryWarning:(NSNotification *)notification
+{
+ if (self.viewAttached) {
+ return;
+ }
+
+ RELEASE_TO_NIL(rowContainerView);
+ for (TiViewProxy* child in [self children]) {
+ [child detachView];
+ }
+}
+
-(void)configureChildren:(UITableViewCell*)cell
{
// this method is called when the cell is initially created
@@ -716,59 +733,63 @@ -(void)configureChildren:(UITableViewCell*)cell
[contentView setFrame:rect];
}
rect.origin = CGPointZero;
- RELEASE_TO_NIL(rowContainerView);
- for (UIView* subview in [[cell contentView] subviews]) {
- if ([subview isKindOfClass:[TiUITableViewRowContainer class]]) {
- rowContainerView = [subview retain];
- break;
- }
- }
- NSArray *rowChildren = [self children];
- if (rowContainerView != nil) {
- __block BOOL canReproxy = YES;
- NSArray *existingSubviews = [rowContainerView subviews];
- if ([rowChildren count] != [existingSubviews count]) {
- canReproxy = NO;
- } else {
- [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
- TiUIView *uiview = [existingSubviews objectAtIndex:idx];
- if (![uiview validateTransferToProxy:proxy deep:YES]) {
- canReproxy = NO;
- *stop = YES;
+ if (self.reusable || (rowContainerView == nil)) {
+ if (self.reusable) {
+ RELEASE_TO_NIL(rowContainerView);
+ for (UIView* subview in [[cell contentView] subviews]) {
+ if ([subview isKindOfClass:[TiUITableViewRowContainer class]]) {
+ rowContainerView = [subview retain];
+ break;
}
- }];
+ }
}
- if (!canReproxy) {
- DebugLog(@"[ERROR] TableViewRow structures for className %@ does not match", self.tableClass);
- [existingSubviews enumerateObjectsUsingBlock:^(TiUIView *child, NSUInteger idx, BOOL *stop) {
- [(TiViewProxy *)child.proxy detachView];
- }];
+ NSArray *rowChildren = [self children];
+ if (self.reusable && (rowContainerView != nil)) {
+ __block BOOL canReproxy = YES;
+ NSArray *existingSubviews = [rowContainerView subviews];
+ if ([rowChildren count] != [existingSubviews count]) {
+ canReproxy = NO;
+ } else {
+ [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
+ TiUIView *uiview = [existingSubviews objectAtIndex:idx];
+ if (![uiview validateTransferToProxy:proxy deep:YES]) {
+ canReproxy = NO;
+ *stop = YES;
+ }
+ }];
+ }
+ if (!canReproxy) {
+ DebugLog(@"[ERROR] TableViewRow structures for className %@ does not match", self.tableClass);
+ [existingSubviews enumerateObjectsUsingBlock:^(TiUIView *child, NSUInteger idx, BOOL *stop) {
+ [(TiViewProxy *)child.proxy detachView];
+ }];
+ }
}
- }
- if (rowContainerView == nil) {
- rowContainerView = [[TiUITableViewRowContainer alloc] initWithFrame:rect];
- [contentView addSubview:rowContainerView];
- }
- [rowContainerView setBackgroundColor:[UIColor clearColor]];
- [rowContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
-
- NSArray *existingSubviews = [rowContainerView subviews];
- [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
- TiUIView *uiview = idx < [existingSubviews count] ? [existingSubviews objectAtIndex:idx] : nil;
- if (!CGRectEqualToRect([proxy sandboxBounds], rect)) {
- [proxy setSandboxBounds:rect];
+ if (rowContainerView == nil) {
+ rowContainerView = [[TiUITableViewRowContainer alloc] initWithFrame:rect];
+ [contentView addSubview:rowContainerView];
}
- [proxy windowWillOpen];
- if (uiview != nil) {
+ [rowContainerView setBackgroundColor:[UIColor clearColor]];
+ [rowContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
+
+ NSArray *existingSubviews = [rowContainerView subviews];
+ [rowChildren enumerateObjectsUsingBlock:^(TiViewProxy *proxy, NSUInteger idx, BOOL *stop) {
+ TiUIView *uiview = idx < [existingSubviews count] ? [existingSubviews objectAtIndex:idx] : nil;
+ if (!CGRectEqualToRect([proxy sandboxBounds], rect)) {
+ [proxy setSandboxBounds:rect];
+ }
+ [proxy windowWillOpen];
[uiview transferProxy:proxy deep:YES];
- }
- [proxy setReproxying:YES];
- [self redelegateViews:proxy toView:contentView];
- if (uiview == nil) {
- [rowContainerView addSubview:[proxy view]];
- }
- [proxy setReproxying:NO];
- }];
+ [proxy setReproxying:YES];
+ [self redelegateViews:proxy toView:contentView];
+ if (uiview == nil) {
+ [rowContainerView addSubview:[proxy view]];
+ }
+ [proxy setReproxying:NO];
+ }];
+ } else {
+ [contentView addSubview:rowContainerView];
+ }
}
configuredChildren = YES;
}
Something went wrong with that request. Please try again.