Fixing massive memory leak in creating content view in table cells. Much faster scrolling now.

This commit is contained in:
Samuel Clay 2013-09-30 12:13:10 -07:00
parent 4bc0c9a3c0
commit 5c4e34e242
9 changed files with 74 additions and 43 deletions

View file

@ -31,6 +31,7 @@
UIColor *feedColorBar;
UIColor *feedColorBarTopBorder;
UIView *cellContent;
}
@property (nonatomic) NSString *siteTitle;

View file

@ -47,6 +47,24 @@ static UIFont *indicatorFont = nil;
}
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
cellContent = [[FeedDetailTableCellView alloc] initWithFrame:self.frame];
cellContent.opaque = YES;
[self.contentView addSubview:cellContent];
[self setupGestures];
}
return self;
}
- (void)drawRect:(CGRect)rect {
((FeedDetailTableCellView *)cellContent).cell = self;
cellContent.frame = rect;
[self setUnreadSwipeIcon];
[cellContent setNeedsDisplay];
}
- (void)setupGestures {
NSString *unreadIcon;
if (storyScore == -1) {
@ -58,7 +76,7 @@ static UIFont *indicatorFont = nil;
}
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
[self setDelegate:appDelegate.feedDetailViewController];
[self setDelegate:(FeedDetailViewController <MCSwipeTableViewCellDelegate> *)appDelegate.feedDetailViewController];
[self setFirstStateIconName:@"clock.png"
firstColor:[UIColor colorWithRed:85.0 / 255.0 green:213.0 / 255.0 blue:80.0 / 255.0 alpha:1.0]
secondStateIconName:nil
@ -80,6 +98,19 @@ static UIFont *indicatorFont = nil;
self.shouldAnimatesIcons = NO;
}
- (void)setUnreadSwipeIcon {
NSString *unreadIcon;
if (storyScore == -1) {
unreadIcon = @"g_icn_hidden.png";
} else if (storyScore == 1) {
unreadIcon = @"g_icn_focus.png";
} else {
unreadIcon = @"g_icn_unread.png";
}
[self setThirdIconName:unreadIcon];
}
@end
@implementation FeedDetailTableCellView

View file

@ -957,13 +957,6 @@
[self.storyTitlesTable selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
FeedDetailTableCellView *content = [[FeedDetailTableCellView alloc]
initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self tableView:self.storyTitlesTable heightForRowAtIndexPath:indexPath])];
content.cell = cell;
[cell.contentView addSubview:content];
[content sizeToFit];
[cell setupGestures];
return cell;
}

View file

@ -12,6 +12,7 @@
#import "NBSwipeableCell.h"
@class NewsBlurAppDelegate;
@class FeedTableCellView;
@interface FeedTableCell : NBSwipeableCell {
NewsBlurAppDelegate *appDelegate;
@ -23,6 +24,7 @@
int _negativeCount;
NSString *_negativeCountStr;
BOOL isSocial;
UIView *cellContent;
}
@property (nonatomic) NewsBlurAppDelegate *appDelegate;

View file

@ -27,32 +27,42 @@ static UIFont *textFont = nil;
+ (void) initialize{
if (self == [FeedTableCell class]) {
textFont = [UIFont boldSystemFontOfSize:18];
// UIColor *psGrad = UIColorFromRGB(0x559F4D);
// UIColor *ntGrad = UIColorFromRGB(0xE4AB00);
// UIColor *ngGrad = UIColorFromRGB(0x9B181B);
// const CGFloat* psTop = CGColorGetComponents(ps.CGColor);
// const CGFloat* psBot = CGColorGetComponents(psGrad.CGColor);
// CGFloat psGradient[] = {
// psTop[0], psTop[1], psTop[2], psTop[3],
// psBot[0], psBot[1], psBot[2], psBot[3]
// };
// psColors = psGradient;
}
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
cellContent = [[FeedTableCellView alloc] initWithFrame:self.frame];
cellContent.opaque = YES;
[self.contentView addSubview:cellContent];
[self setupGestures];
}
return self;
}
- (void)drawRect:(CGRect)rect {
((FeedTableCellView *)cellContent).cell = self;
cellContent.frame = rect;
[cellContent setNeedsDisplay];
}
- (void)prepareForReuse {
[super prepareForReuse];
}
- (void) setPositiveCount:(int)ps {
if (ps == _positiveCount) return;
_positiveCount = ps;
[self setNeedsDisplay];
[cellContent setNeedsDisplay];
}
- (void) setNeutralCount:(int)nt {
if (nt == _neutralCount) return;
_neutralCount = nt;
[self setNeedsDisplay];
[cellContent setNeedsDisplay];
}
- (void) setNegativeCount:(int)ng {
@ -60,16 +70,16 @@ static UIFont *textFont = nil;
_negativeCount = ng;
_negativeCountStr = [NSString stringWithFormat:@"%d", ng];
[self setNeedsDisplay];
[cellContent setNeedsDisplay];
}
- (void)setupGestures {
[self setDelegate:appDelegate.feedsViewController];
[self setFirstStateIconName:@"clock.png"
[self setDelegate:(NewsBlurViewController <MCSwipeTableViewCellDelegate> *)appDelegate.feedsViewController];
[self setFirstStateIconName:@"train.png"
firstColor:[UIColor colorWithRed:85.0 / 255.0 green:213.0 / 255.0 blue:80.0 / 255.0 alpha:1.0]
secondStateIconName:nil
secondColor:nil
thirdIconName:@"clock.png"
thirdIconName:@"g_icn_unread.png"
thirdColor:[UIColor colorWithRed:254.0 / 255.0 green:217.0 / 255.0 blue:56.0 / 255.0 alpha:1.0]
fourthIconName:nil
fourthColor:nil];

View file

@ -34,11 +34,11 @@
#import "UIImageView+AFNetworking.h"
#import "NBBarButtonItem.h"
#define kPhoneTableViewRowHeight 31;
#define kTableViewRowHeight 31;
#define kBlurblogTableViewRowHeight 32;
#define kPhoneBlurblogTableViewRowHeight 32;
static const CGFloat kFolderTitleHeight = 28;
static const CGFloat kPhoneTableViewRowHeight = 31.0f;
static const CGFloat kTableViewRowHeight = 31.0f;
static const CGFloat kBlurblogTableViewRowHeight = 32.0f;
static const CGFloat kPhoneBlurblogTableViewRowHeight = 32.0f;
static const CGFloat kFolderTitleHeight = 28.0f;
@interface NewsBlurViewController ()
@ -883,14 +883,6 @@ static const CGFloat kFolderTitleHeight = 28;
cell.negativeCount = [[unreadCounts objectForKey:@"ng"] intValue];
cell.isSocial = isSocial;
FeedTableCellView *content = [[FeedTableCellView alloc]
initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self tableView:self.feedTitlesTable heightForRowAtIndexPath:indexPath])];
content.cell = cell;
[cell.contentView addSubview:content];
[content sizeToFit];
[cell setupGestures];
return cell;
}

View file

@ -119,9 +119,9 @@
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
- (void)requestFinished:(ASIHTTPRequest *)_request {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSString *responseString = [request responseString];
NSString *responseString = [_request responseString];
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *results = [NSJSONSerialization
@ -156,8 +156,8 @@
[self.view addSubview:self.profileTable];
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
- (void)requestFailed:(ASIHTTPRequest *)_request {
NSError *error = [_request error];
NSLog(@"Error: %@", error);
[appDelegate informError:error];
}

View file

@ -1033,6 +1033,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
78095E45128EF37E00230C8E /* SystemConfiguration.framework in Frameworks */,
FF4EE9A4175EC9CF005891B5 /* libsqlite3.dylib in Frameworks */,
FFDCA0C316E80952000D8E0C /* AdSupport.framework in Frameworks */,
FFDCA0C116E8094F000D8E0C /* Accounts.framework in Frameworks */,
@ -1048,7 +1049,6 @@
788EF356127E5BC80088EDC5 /* QuartzCore.framework in Frameworks */,
78095E3F128EF35400230C8E /* CFNetwork.framework in Frameworks */,
78095E43128EF37E00230C8E /* MobileCoreServices.framework in Frameworks */,
78095E45128EF37E00230C8E /* SystemConfiguration.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -2,8 +2,10 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Underscore.h"
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#define DEBUG 1
//#define DEBUG 1
#ifdef DEBUG
#define BACKGROUND_REFRESH_SECONDS -5