Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactorings - memory issues

  • Loading branch information...
commit ada11ca6cfa3ac77e57e71d663a36ce83e33f440 1 parent 260bbf0
@TheVole authored
View
20 Classes/HorizontalTableView.m
@@ -117,7 +117,7 @@ - (UIView *)dequeueColumnView {
[self.columnPool removeLastObject];
DLog(@"Supply from reuse pool");
}
- return vw;
+ return [vw autorelease];
}
- (void)removeColumn:(NSInteger)index {
@@ -183,14 +183,20 @@ - (void)prepareView {
_columnWidth = nil;
[self setClipsToBounds:YES];
- self.scrollView = [[[UIScrollView alloc] init] autorelease];
+ self.autoresizesSubviews = YES;
+
+ UIScrollView *scroller = [[UIScrollView alloc] init];
CGRect rect = self.bounds;
- self.scrollView.frame = rect;
- self.scrollView.delegate = self;
+ scroller.frame = rect;
+ scroller.delegate = self;
+ scroller.autoresizesSubviews = YES;
+
//self.scrollView.pagingEnabled = YES;
- self.scrollView.showsHorizontalScrollIndicator = NO;
- self.scrollView.showsVerticalScrollIndicator = NO;
- [self addSubview:self.scrollView];
+ scroller.showsHorizontalScrollIndicator = YES;
+ scroller.showsVerticalScrollIndicator = YES;
+ self.scrollView = scroller;
+ [self addSubview:scroller];
+ [scroller release], scroller = nil;
[self refreshData];
}
View
3  Classes/PageLoopViewController.h
@@ -13,8 +13,11 @@
HorizontalTableView *tableView;
NSArray *colors;
+
+ UIView *columnView;
}
@property (nonatomic, retain) IBOutlet HorizontalTableView *tableView;
+@property (nonatomic, retain) IBOutlet UIView *columnView;
@end
View
24 Classes/PageLoopViewController.m
@@ -12,6 +12,7 @@
@implementation PageLoopViewController
@synthesize tableView;
+@synthesize columnView;
#pragma mark -
#pragma mark Memory management
@@ -29,11 +30,13 @@ - (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
self.tableView = nil;
+ self.columnView = nil;
}
- (void)dealloc {
[tableView release], tableView = nil;
+ [columnView release], columnView = nil;
[super dealloc];
}
@@ -85,23 +88,14 @@ - (NSInteger)numberOfColumnsForTableView:(HorizontalTableView *)tableView {
- (UIView *)tableView:(HorizontalTableView *)aTableView viewForIndex:(NSInteger)index {
- CGFloat height = aTableView.bounds.size.height;
- CGFloat width = 150.0f;
-
UIView *vw = [aTableView dequeueColumnView];
if (!vw) {
DLog(@"Constructing new view");
- vw = [[UIView alloc] init];
- vw.frame = CGRectMake(0.0f, 0.0f, width, height);
- vw.contentMode = UIViewContentModeScaleToFill;
- UILabel *lbl = [[UILabel alloc] initWithFrame:vw.bounds];
- lbl.text = [NSString stringWithFormat:@"%d", index];
- lbl.textColor = [UIColor redColor];
- lbl.tag = 1234;
- lbl.backgroundColor = [UIColor clearColor];
- lbl.textAlignment = UITextAlignmentCenter;
- lbl.font = [UIFont boldSystemFontOfSize:24.0f];
- [vw addSubview:lbl];
+
+ [[NSBundle mainBundle] loadNibNamed:@"ColumnView" owner:self options:nil];
+ vw = self.columnView;
+ self.columnView = nil;
+
}
[vw setBackgroundColor:[colors objectAtIndex:index]];
@@ -109,7 +103,7 @@ - (UIView *)tableView:(HorizontalTableView *)aTableView viewForIndex:(NSInteger)
UILabel *lbl = (UILabel *)[vw viewWithTag:1234];
lbl.text = [NSString stringWithFormat:@"%d", index];
- return [vw autorelease];
+ return vw;
}
- (CGFloat)columnWidthForTableView:(HorizontalTableView *)tableView {
View
4 Scroller.xcodeproj/project.pbxproj
@@ -15,6 +15,7 @@
5B18624E11A951930028EB1E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B18624D11A951930028EB1E /* QuartzCore.framework */; };
5B50846C11A6E69200791658 /* HorizontalTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B50846B11A6E69200791658 /* HorizontalTableView.m */; };
5B5084E811A6EB8800791658 /* ipadicon.png in Resources */ = {isa = PBXBuildFile; fileRef = 5B5084E711A6EB8800791658 /* ipadicon.png */; };
+ 5B83CCE911A992F2002573B0 /* ColumnView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B83CCE811A992F2002573B0 /* ColumnView.xib */; };
5B88014B11A88BA400C7895C /* PageLoopViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B88014911A88BA400C7895C /* PageLoopViewController.m */; };
5B88014C11A88BA400C7895C /* PageLoopViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5B88014A11A88BA400C7895C /* PageLoopViewController.xib */; };
/* End PBXBuildFile section */
@@ -32,6 +33,7 @@
5B50846A11A6E69200791658 /* HorizontalTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HorizontalTableView.h; sourceTree = "<group>"; };
5B50846B11A6E69200791658 /* HorizontalTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HorizontalTableView.m; sourceTree = "<group>"; };
5B5084E711A6EB8800791658 /* ipadicon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ipadicon.png; sourceTree = "<group>"; };
+ 5B83CCE811A992F2002573B0 /* ColumnView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ColumnView.xib; sourceTree = "<group>"; };
5B88014811A88BA400C7895C /* PageLoopViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageLoopViewController.h; sourceTree = "<group>"; };
5B88014911A88BA400C7895C /* PageLoopViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PageLoopViewController.m; sourceTree = "<group>"; };
5B88014A11A88BA400C7895C /* PageLoopViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = PageLoopViewController.xib; path = Classes/PageLoopViewController.xib; sourceTree = "<group>"; };
@@ -102,6 +104,7 @@
5B88014A11A88BA400C7895C /* PageLoopViewController.xib */,
5B5084E711A6EB8800791658 /* ipadicon.png */,
8D1107310486CEB800E47090 /* Scroller-Info.plist */,
+ 5B83CCE811A992F2002573B0 /* ColumnView.xib */,
);
name = Resources;
sourceTree = "<group>";
@@ -160,6 +163,7 @@
files = (
5B5084E811A6EB8800791658 /* ipadicon.png in Resources */,
5B88014C11A88BA400C7895C /* PageLoopViewController.xib in Resources */,
+ 5B83CCE911A992F2002573B0 /* ColumnView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Please sign in to comment.
Something went wrong with that request. Please try again.