Permalink
Browse files

[UI] Don't retain navigators in table view cells. Pass them to the se…

…tObject method instead.

This resolves the problem brought up in 72c9f3a.
  • Loading branch information...
jverkoey committed Apr 17, 2011
1 parent f89498e commit 883e71f8069726d7fd625fc3339cc7022fc8e450
@@ -23,11 +23,8 @@
@interface TTTableLinkedItemCell : TTTableViewCell {
TTTableLinkedItem* _item;
- TTBaseNavigator* _navigator;
}
-@property (nonatomic, retain) TTBaseNavigator* navigator;
-
+ (UITableViewCellAccessoryType)accessoryTypeForObject:(id)object URLMap:(TTURLMap*)URLMap;
+ (UITableViewCellSelectionStyle)selectionStyleForObject:(id)object;
@@ -25,6 +25,8 @@ extern const CGFloat kTableCellVPadding;
extern const NSInteger kTableMessageTextLineCount;
extern const CGFloat kTableDisclosureIndicatorWidth;
+@class TTBaseNavigator;
+
/**
* The base class for table cells which are single-object based.
*
@@ -41,6 +43,12 @@ extern const CGFloat kTableDisclosureIndicatorWidth;
@property (nonatomic, retain) id object;
+/**
+ * @param object The table data source's object that was used to create this cell.
+ * @param navigator The table view's navigator. Necessary for linked cells.
+ */
+- (void)setObject:(id)object navigator:(TTBaseNavigator*)navigator;
+
/**
* Measure the height of the row with the object that will be assigned to the cell.
*/
@@ -19,6 +19,8 @@
// Network
#import "Three20Network/TTModel.h"
+@class TTBaseNavigator;
+
@protocol TTTableViewDataSource <UITableViewDataSource, TTModel, UISearchDisplayDelegate>
/**
@@ -78,7 +80,8 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
@interface TTTableViewDataSource : NSObject <TTTableViewDataSource> {
- id<TTModel> _model;
+ id<TTModel> _model;
+ TTBaseNavigator* _navigator;
}
@end
@@ -36,12 +36,9 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTTableLinkedItemCell
-@synthesize navigator = _navigator;
-
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
- TT_RELEASE_SAFELY(_navigator);
TT_RELEASE_SAFELY(_item);
[super dealloc];
@@ -107,26 +104,18 @@ - (void)setObject:(id)object {
if (_item != object) {
[_item release];
_item = [object retain];
-
- self.accessoryType = [[self class] accessoryTypeForObject:object URLMap:self.navigator.URLMap];
- self.selectionStyle = [[self class] selectionStyleForObject:object];
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-#pragma mark -
-#pragma mark Properties
-
+- (void)setObject:(id)object navigator:(TTBaseNavigator*)navigator {
+ if (_item != object) {
+ [self setObject:object];
-///////////////////////////////////////////////////////////////////////////////////////////////////
-- (TTBaseNavigator*)navigator {
- if (nil == _navigator) {
- self.navigator = [TTNavigator navigator];
+ self.accessoryType = [[self class] accessoryTypeForObject:object URLMap:navigator.URLMap];
+ self.selectionStyle = [[self class] selectionStyleForObject:object];
}
-
- return _navigator;
}
@@ -66,4 +66,10 @@ - (void)setObject:(id)object {
}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+- (void)setObject:(id)object navigator:(TTBaseNavigator*)navigator {
+ [self setObject:object];
+}
+
+
@end
@@ -73,6 +73,7 @@ @implementation TTTableViewDataSource
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
TT_RELEASE_SAFELY(_model);
+ TT_RELEASE_SAFELY(_navigator);
[super dealloc];
}
@@ -118,7 +119,19 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
///////////////////////////////////////////////////////////////////////////////////////////////////
- (UITableViewCell*)tableView:(UITableView *)tableView
- cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ if (nil == _navigator) {
+ TTBaseNavigator* navigator = [TTBaseNavigator navigatorForView:tableView];
+ if (_navigator != navigator) {
+ [_navigator release];
+ _navigator = [navigator retain];
+ }
+ if (nil == _navigator) {
+ // Default the the global navigator if this table isn't attached to a view hierarchy.
+ _navigator = [TTBaseNavigator globalNavigator];
+ }
+ }
+
id object = [self tableView:tableView objectForRowAtIndexPath:indexPath];
Class cellClass = [self tableView:tableView cellClassForObject:object];
@@ -136,10 +149,8 @@ - (UITableViewCell*)tableView:(UITableView *)tableView
[identifier release];
if ([cell isKindOfClass:[TTTableViewCell class]]) {
- if ([cell isKindOfClass:[TTTableLinkedItemCell class]]) {
- [(TTTableLinkedItemCell*)cell setNavigator:[TTBaseNavigator navigatorForView:tableView]];
- }
- [(TTTableViewCell*)cell setObject:object];
+ [(TTTableViewCell*)cell setObject: object
+ navigator: _navigator];
}
[self tableView:tableView cell:cell willAppearAtIndexPath:indexPath];

0 comments on commit 883e71f

Please sign in to comment.