From 60218e519b940408901b8d06c5dee1b2c624cb37 Mon Sep 17 00:00:00 2001 From: k-be Date: Fri, 7 Feb 2014 12:49:59 +0700 Subject: [PATCH 1/3] fixed some bugs added arc competition and arm64 --- Classes/HorizontalTableView.h | 6 +- Classes/HorizontalTableView.m | 235 ++++++++++++++++++++--------- Classes/PageLoopViewController.m | 66 ++++---- Classes/ScrollerAppDelegate.m | 10 +- Default-568h@2x.png | Bin 0 -> 18594 bytes Scroller.xcodeproj/project.pbxproj | 38 +++++ libs/Memory/Memory.h | 68 +++++++++ libs/Memory/Memory.m | 49 ++++++ main.m | 14 +- 9 files changed, 363 insertions(+), 123 deletions(-) create mode 100644 Default-568h@2x.png create mode 100644 libs/Memory/Memory.h create mode 100644 libs/Memory/Memory.m diff --git a/Classes/HorizontalTableView.h b/Classes/HorizontalTableView.h index 9cc821f..6251c8f 100644 --- a/Classes/HorizontalTableView.h +++ b/Classes/HorizontalTableView.h @@ -22,6 +22,8 @@ // OR OTHER DEALINGS IN THE SOFTWARE. #import +#import "Memory.h" + @class HorizontalTableView; @@ -44,12 +46,10 @@ NSInteger _visibleColumnCount; NSNumber *_columnWidth; - id _delegate; - NSMutableArray *_columnPool; } -@property (assign) IBOutlet id delegate; +@property (MWeakProperty) IBOutlet id delegate; - (void)refreshData; - (UIView *)dequeueColumnView; diff --git a/Classes/HorizontalTableView.m b/Classes/HorizontalTableView.m index df805f1..8ba512e 100644 --- a/Classes/HorizontalTableView.m +++ b/Classes/HorizontalTableView.m @@ -23,6 +23,7 @@ #import "HorizontalTableView.h" + #define kColumnPoolSize 3 @interface HorizontalTableView() @@ -44,6 +45,13 @@ - (void)removeColumn:(NSInteger)index; @end +@interface HorizontalTableView (Private) + +- (void)_removePages; + +@end + + @implementation HorizontalTableView @synthesize pageViews=_pageViews; @@ -53,103 +61,146 @@ @implementation HorizontalTableView @synthesize columnPool=_columnPool; - -- (void)refreshData { +- (void)refreshData +{ + [self _removePages]; self.pageViews = [NSMutableArray array]; // to save time and memory, we won't load the page views immediately NSUInteger numberOfPhysicalPages = [self numberOfPages]; for (NSUInteger i = 0; i < numberOfPhysicalPages; ++i) + { [self.pageViews addObject:[NSNull null]]; - + } + [self setNeedsLayout]; } -- (NSUInteger)numberOfPages { + +- (NSUInteger)numberOfPages +{ NSInteger numPages = 0; - if (_delegate) + + if (_delegate) + { numPages = [_delegate numberOfColumnsForTableView:self]; - return numPages; + } + + return numPages; } -- (UIView *)viewForPhysicalPage:(NSUInteger)pageIndex { + +- (UIView *)viewForPhysicalPage:(NSUInteger)pageIndex +{ NSParameterAssert(pageIndex >= 0); NSParameterAssert(pageIndex < [self.pageViews count]); UIView *pageView; - if ([self.pageViews objectAtIndex:pageIndex] == [NSNull null]) { - - if (_delegate) { + if ([self.pageViews objectAtIndex:pageIndex] == [NSNull null]) + { + if (_delegate) + { pageView = [_delegate tableView:self viewForIndex:pageIndex]; [self.pageViews replaceObjectAtIndex:pageIndex withObject:pageView]; [self.scrollView addSubview:pageView]; DLog(@"View loaded for page %d", pageIndex); } - } else { + } + else + { pageView = [self.pageViews objectAtIndex:pageIndex]; } + return pageView; } -- (CGSize)pageSize { - CGRect rect = self.scrollView.bounds; + +- (CGSize)pageSize +{ + CGRect rect = self.scrollView.bounds; return rect.size; } -- (CGFloat)columnWidth { - if (!_columnWidth) { - if (_delegate) { - CGFloat width = [_delegate columnWidthForTableView:self]; - _columnWidth = [[NSNumber numberWithFloat:width] retain]; + +- (CGFloat)columnWidth +{ + if (!_columnWidth) + { + if (_delegate) + { + CGFloat width = [_delegate columnWidthForTableView:self]; + MASSIGN_RETAIN(_columnWidth, @(width)); } } + return [_columnWidth floatValue]; - } -- (BOOL)isPhysicalPageLoaded:(NSUInteger)pageIndex { - return [self.pageViews objectAtIndex:pageIndex] != [NSNull null]; + +- (BOOL)isPhysicalPageLoaded:(NSUInteger)pageIndex +{ + BOOL isLoaded = [self.pageViews objectAtIndex:pageIndex] != [NSNull null]; + return isLoaded; } -- (void)layoutPhysicalPage:(NSUInteger)pageIndex { + +- (void)layoutPhysicalPage:(NSUInteger)pageIndex +{ UIView *pageView = [self viewForPhysicalPage:pageIndex]; - CGFloat viewWidth = pageView.bounds.size.width; + CGFloat viewWidth = pageView.bounds.size.width; CGSize pageSize = [self pageSize]; - - CGRect rect = CGRectMake(viewWidth * pageIndex, 0, viewWidth, pageSize.height); + + CGRect rect = CGRectMake(viewWidth * pageIndex, 0, viewWidth, pageSize.height); pageView.frame = rect; } -- (void)awakeFromNib { - [self prepareView]; + +- (void)awakeFromNib +{ + [super awakeFromNib]; + [self prepareView]; } -- (void)queueColumnView:(UIView *)vw { - if ([self.columnPool count] >= kColumnPoolSize) { + +- (void)queueColumnView:(UIView *)vw +{ + if ([self.columnPool count] >= kColumnPoolSize) + { return; } + [self.columnPool addObject:vw]; } -- (UIView *)dequeueColumnView { - UIView *vw = [[self.columnPool lastObject] retain]; - if (vw) { + +- (UIView *)dequeueColumnView +{ + UIView *vw = nil; + MASSIGN_RETAIN(vw, [self.columnPool lastObject]); + if (vw) + { [self.columnPool removeLastObject]; DLog(@"Supply from reuse pool"); - } - return [vw autorelease]; + } + + return MReturnAutoreleased(vw); } -- (void)removeColumn:(NSInteger)index { - if ([self.pageViews objectAtIndex:index] != [NSNull null]) { - DLog(@"Removing view at position %d", index); - UIView *vw = [self.pageViews objectAtIndex:index]; - [self queueColumnView:vw]; - [vw removeFromSuperview]; - [self.pageViews replaceObjectAtIndex:index withObject:[NSNull null]]; - } + +- (void)removeColumn:(NSInteger)index +{ + if ([self.pageViews objectAtIndex:index] != [NSNull null]) + { + DLog(@"Removing view at position %d", index); + UIView *vw = [self.pageViews objectAtIndex:index]; + [self queueColumnView:vw]; + [vw removeFromSuperview]; + [self.pageViews replaceObjectAtIndex:index withObject:[NSNull null]]; + } } -- (void)currentPageIndexDidChange { + +- (void)currentPageIndexDidChange +{ CGSize pageSize = [self pageSize]; CGFloat columnWidth = [self columnWidth]; _visibleColumnCount = pageSize.width / columnWidth + 2; @@ -157,50 +208,62 @@ - (void)currentPageIndexDidChange { NSInteger leftMostPageIndex = -1; NSInteger rightMostPageIndex = 0; - for (NSInteger i = -2; i < _visibleColumnCount; i++) { + for (NSInteger i = -2; i < _visibleColumnCount; i++) + { NSInteger index = _currentPhysicalPageIndex + i; - if (index < [self.pageViews count] && (index >= 0)) { + if (index < [self.pageViews count] && (index >= 0)) + { [self layoutPhysicalPage:index]; if (leftMostPageIndex < 0) - leftMostPageIndex = index; + { + leftMostPageIndex = index; + } rightMostPageIndex = index; } } // clear out views to the left - for (NSInteger i = 0; i < leftMostPageIndex; i++) { + for (NSInteger i = 0; i < leftMostPageIndex; i++) + { [self removeColumn:i]; } // clear out views to the right - for (NSInteger i = rightMostPageIndex + 1; i < [self.pageViews count]; i++) { + for (NSInteger i = rightMostPageIndex + 1; i < [self.pageViews count]; i++) + { [self removeColumn:i]; } - - } -- (void)layoutPages { + +- (void)layoutPages +{ CGSize pageSize = self.bounds.size; self.scrollView.contentSize = CGSizeMake([self.pageViews count] * [self columnWidth], pageSize.height); } -- (id)init { + +- (id)init +{ self = [super init]; - if (self) { + if (self) + { [self prepareView]; } + return self; } -- (void)prepareView { - _columnPool = [[NSMutableArray alloc] initWithCapacity:kColumnPoolSize]; - _columnWidth = nil; + +- (void)prepareView +{ + MASSIGN_RETAIN(_columnPool, [NSMutableArray arrayWithCapacity:kColumnPoolSize]); + MRELEASE_NIL(_columnWidth); [self setClipsToBounds:YES]; self.autoresizesSubviews = YES; - UIScrollView *scroller = [[UIScrollView alloc] init]; + UIScrollView *scroller = MReturnAutoreleased([[UIScrollView alloc] init]); CGRect rect = self.bounds; scroller.frame = rect; scroller.backgroundColor = [UIColor blackColor]; @@ -214,16 +277,18 @@ - (void)prepareView { scroller.alwaysBounceVertical = NO; self.scrollView = scroller; [self addSubview:scroller]; - [scroller release], scroller = nil; } -- (NSUInteger)physicalPageIndex { +- (NSUInteger)physicalPageIndex +{ NSUInteger page = self.scrollView.contentOffset.x / [self columnWidth]; return page; } -- (void)setPhysicalPageIndex:(NSUInteger)newIndex { + +- (void)setPhysicalPageIndex:(NSUInteger)newIndex +{ self.scrollView.contentOffset = CGPointMake(newIndex * [self pageSize].width, 0); } @@ -231,7 +296,8 @@ - (void)setPhysicalPageIndex:(NSUInteger)newIndex { #pragma mark - #pragma mark UIScrollViewDelegate methods -- (void)scrollViewDidScroll:(UIScrollView *)scrollView { +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ //DLog(@"Did Scroll"); NSUInteger newPageIndex = self.physicalPageIndex; @@ -245,24 +311,33 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { DLog(@"CSize = %@", NSStringFromCGSize(rect)); } -- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { + +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate +{ } -- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { + +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ DLog(@"scrollViewDidEndDecelerating"); } -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -- (void)layoutSubviews { +- (void)layoutSubviews +{ [self layoutPages]; [self currentPageIndexDidChange]; } -- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { + +- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation +{ // adjust frames according to the new page size - this does not cause any visible changes [self layoutPages]; self.physicalPageIndex = _currentPhysicalPageIndex; @@ -278,12 +353,28 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO } -- (void)dealloc { - [_columnPool release], _columnPool = nil; - [_columnWidth release], _columnWidth = nil; - [_pageViews release], _pageViews = nil; - [_scrollView release], _scrollView = nil; - [super dealloc]; +- (void)dealloc +{ + MRELEASE_NIL(_columnPool); + MRELEASE_NIL(_columnWidth); + MRELEASE_NIL(_pageViews); + MRELEASE_NIL(_scrollView); + MSuperDealloc; +} + +@end + + +#pragma mark - +@implementation HorizontalTableView (Private) + +- (void)_removePages +{ + [self.pageViews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [obj removeFromSuperview]; + }]; + + [self.pageViews removeAllObjects]; } @end diff --git a/Classes/PageLoopViewController.m b/Classes/PageLoopViewController.m index d579e84..021bd27 100644 --- a/Classes/PageLoopViewController.m +++ b/Classes/PageLoopViewController.m @@ -23,6 +23,8 @@ #import "PageLoopViewController.h" #import +#import "Memory.h" + @implementation PageLoopViewController @@ -32,16 +34,8 @@ @implementation PageLoopViewController #pragma mark - #pragma mark Memory management - -- (void)didReceiveMemoryWarning { - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - - -- (void)viewDidUnload { +- (void)viewDidUnload +{ [super viewDidUnload]; // Release any retained subviews of the main view. self.tableView = nil; @@ -49,27 +43,18 @@ - (void)viewDidUnload { } -- (void)dealloc { - [tableView release], tableView = nil; - [columnView release], columnView = nil; - [super dealloc]; +- (void)dealloc +{ + tableView.delegate = nil; + MRELEASE_NIL(tableView); + MRELEASE_NIL(columnView); + MSuperDealloc; } #pragma mark - - -/* - // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - // Custom initialization - } - return self; -} -*/ - - // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -- (void)viewDidLoad { +- (void)viewDidLoad +{ [super viewDidLoad]; CALayer *layer = [self.tableView layer]; @@ -78,19 +63,20 @@ - (void)viewDidLoad { NSMutableArray *colorArray = [[NSMutableArray alloc] init]; NSInteger step = 5; - for (NSInteger i = 0; i < 255; i += step) { + for (NSInteger i = 0; i < 255; i += step) + { CGFloat f = (float)i/255.0f; UIColor *clr = [UIColor colorWithRed:f green:f blue:f alpha:1.0f]; [colorArray addObject:clr]; } + colors = colorArray; - // [self.tableView refreshData]; [self.tableView performSelector:@selector(refreshData) withObject:nil afterDelay:0.3f]; } - -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ // Overriden to allow any orientation. return YES; } @@ -98,14 +84,17 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface #pragma mark - #pragma mark HorizontalTableViewDelegate methods -- (NSInteger)numberOfColumnsForTableView:(HorizontalTableView *)tableView { +- (NSInteger)numberOfColumnsForTableView:(HorizontalTableView *)tableView +{ return [colors count]; } -- (UIView *)tableView:(HorizontalTableView *)aTableView viewForIndex:(NSInteger)index { - - UIView *vw = [aTableView dequeueColumnView]; - if (!vw) { + +- (UIView *)tableView:(HorizontalTableView *)aTableView viewForIndex:(NSInteger)index +{ + UIView *vw = [aTableView dequeueColumnView]; + if (!vw) + { DLog(@"Constructing new view"); [[NSBundle mainBundle] loadNibNamed:@"ColumnView" owner:self options:nil]; @@ -114,7 +103,6 @@ - (UIView *)tableView:(HorizontalTableView *)aTableView viewForIndex:(NSInteger) } [vw setBackgroundColor:[colors objectAtIndex:index]]; - UILabel *lbl = (UILabel *)[vw viewWithTag:1234]; lbl.text = [NSString stringWithFormat:@"%d", index]; @@ -122,7 +110,9 @@ - (UIView *)tableView:(HorizontalTableView *)aTableView viewForIndex:(NSInteger) return vw; } -- (CGFloat)columnWidthForTableView:(HorizontalTableView *)tableView { + +- (CGFloat)columnWidthForTableView:(HorizontalTableView *)tableView +{ return 150.0f; } diff --git a/Classes/ScrollerAppDelegate.m b/Classes/ScrollerAppDelegate.m index 1a55e01..08d534e 100644 --- a/Classes/ScrollerAppDelegate.m +++ b/Classes/ScrollerAppDelegate.m @@ -23,12 +23,13 @@ #import "ScrollerAppDelegate.h" #import "PageLoopViewController.h" +#import "Memory.h" @implementation ScrollerAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - + viewController = [[PageLoopViewController alloc] init]; window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; @@ -42,9 +43,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( - (void)dealloc { - [viewController release]; - [window release]; - [super dealloc]; + MRELEASE_NIL(viewController); + MRELEASE_NIL(window); + + MSuperDealloc; } diff --git a/Default-568h@2x.png b/Default-568h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0891b7aabfcf3422423b109c8beed2bab838c607 GIT binary patch literal 18594 zcmeI4X;f257Jx&9fS`ixvS;&$x8J@slQFSel)6zJN=?13FB7H(lQjRkSy8x_-S~tvu2gzn1oS+dLcF#eqtq$ z%tf9TTvX?`)R@}3uBI;jzS-=ZR-Td&MHaS&;!0?Ni*#$#`n*~CcQK)Q9vAQ~TUpnI!j)a2biYK^R)M~A5wUDZhx?ULMX z3x1P&qt=trOY6P2U67L=m=U?F|5#Uj(eCueNTZaHs_ceWiHeET+j+tp3Jt9g(ekqP z2WOvfR{qV+9r+o4J5?qK>7;;^+I7tGv-i)es$X_D=EoKF+S?zsyj^oRFElP}c}JT< zd8SUs-?O?}2YD#ngKbnHgzHBcboxK_2r9l(?eNCl-pEzkJm}fY?WC*jnS?VBE4EpY zO$fEejz6fU;W2Kl>JeQBZBl-%Irg`obSlg*@4QB;Dd1H7^Oi5wvt4d{RZ!8Og?^aE z)k0$1g+V3fd(gdQ3d&q2q-FL*uy#}|bc^=VhFsl0jBgUGJ+-s3U8MK9A!YJJMxpci z5hJ%|{DwV48fZn0{n5l$N_KcSb#NKE4plB`9I6Zt=Z!~-zw0{9tg$L&Ju1F0X)Cy8 zKF;(&lJ>x)Jw(=;p~sF(Sd9VWGwFE2rnyS9!f^DZ8+aCLq zQ};>lcJ1GDLqjm6Hd>|Eabno@P`~Bn(~6^aD_#yoEH(a?Nm1S<;S+hSxI5d16^<1lEM3NPFi zkqPrpL)+ zgnseFikg`gJVBha1&7C4;O6>h=dt~`ND+;Zd?W(4v2JIb7Pt>Td42%M-Ju-XAH#Pns762L}K3 zDhvsRqN0Ni(1UrishD2YvV?4*h2iFj$+&N||Fn$4n|^NSU+o?~jq`0jVQt8T9l{7b zXiwwODFh2V!Q6sqP9S>WH$oOf$N~=d0-bqTlD61!=`&0eAP-F>XN?*|gtOXX{ zQVTWyYo4ZK0GAw!GHf|pz9`D;-bbb*5LBX*{bnz|+)$@&P9|ORM2o?95{;ejvo&r- zq8cBhTN6nn)7~W>54U)%-F_-b?YKdfk5I8MHcuzBD5)!;yv#Z&R&^y=@=>VTIMy#r zX&U<=BsPkdqcMe<_}2+>H%XKyrr5ZR8_KVe>ZqYN z^=^~TFD};;rHJ$U;{~w^hYojl4hRI@SH$^K{YEo=sg)WY87r!*7blQK&qnpDo0`Vn zkl)9u9g=mCh&ZCJS(L4yN3k0kQ zuvg$h2KEEk51T+O0JQ+r0`R>g{jvqM0Mr6d3qUOZwE!?PI7HY@CE|dr sfw?Q;rAv?G4&^^8-z_>&sWXMxvD*gPOU4CBe-*@OtE+wfmVJNyHv)PfH~;_u literal 0 HcmV?d00001 diff --git a/Scroller.xcodeproj/project.pbxproj b/Scroller.xcodeproj/project.pbxproj index eafdcb6..38ec5ce 100755 --- a/Scroller.xcodeproj/project.pbxproj +++ b/Scroller.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1356407B18A4A58B0008C9EC /* Memory.m in Sources */ = {isa = PBXBuildFile; fileRef = 1356407A18A4A58B0008C9EC /* Memory.m */; }; + 1356407D18A4AB620008C9EC /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1356407C18A4AB620008C9EC /* Default-568h@2x.png */; }; 1D3623260D0F684500981E51 /* ScrollerAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* ScrollerAppDelegate.m */; }; 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; @@ -21,6 +23,9 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1356407918A4A58B0008C9EC /* Memory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Memory.h; sourceTree = ""; }; + 1356407A18A4A58B0008C9EC /* Memory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Memory.m; sourceTree = ""; }; + 1356407C18A4AB620008C9EC /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 1D3623240D0F684500981E51 /* ScrollerAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollerAppDelegate.h; sourceTree = ""; }; 1D3623250D0F684500981E51 /* ScrollerAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScrollerAppDelegate.m; sourceTree = ""; }; @@ -68,6 +73,23 @@ path = Classes; sourceTree = ""; }; + 1356407718A4A58B0008C9EC /* libs */ = { + isa = PBXGroup; + children = ( + 1356407818A4A58B0008C9EC /* Memory */, + ); + path = libs; + sourceTree = ""; + }; + 1356407818A4A58B0008C9EC /* Memory */ = { + isa = PBXGroup; + children = ( + 1356407918A4A58B0008C9EC /* Memory.h */, + 1356407A18A4A58B0008C9EC /* Memory.m */, + ); + path = Memory; + sourceTree = ""; + }; 19C28FACFE9D520D11CA2CBB /* Products */ = { isa = PBXGroup; children = ( @@ -79,6 +101,8 @@ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( + 1356407C18A4AB620008C9EC /* Default-568h@2x.png */, + 1356407718A4A58B0008C9EC /* libs */, 080E96DDFE201D6D7F000001 /* Classes */, 29B97315FDCFA39411CA2CEA /* Other Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, @@ -144,9 +168,15 @@ /* Begin PBXProject section */ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; + attributes = { + }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Scroller" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + en, + ); mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; projectDirPath = ""; projectRoot = ""; @@ -162,6 +192,7 @@ buildActionMask = 2147483647; files = ( 5B5084E811A6EB8800791658 /* ipadicon.png in Resources */, + 1356407D18A4AB620008C9EC /* Default-568h@2x.png in Resources */, 5B88014C11A88BA400C7895C /* PageLoopViewController.xib in Resources */, 5B83CCE911A992F2002573B0 /* ColumnView.xib in Resources */, ); @@ -177,6 +208,7 @@ 1D60589B0D05DD56006BFB54 /* main.m in Sources */, 1D3623260D0F684500981E51 /* ScrollerAppDelegate.m in Sources */, 5B50846C11A6E69200791658 /* HorizontalTableView.m in Sources */, + 1356407B18A4A58B0008C9EC /* Memory.m in Sources */, 5B88014B11A88BA400C7895C /* PageLoopViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -195,6 +227,7 @@ GCC_PREFIX_HEADER = Scroller_Prefix.pch; INFOPLIST_FILE = "Scroller-Info.plist"; PRODUCT_NAME = Scroller; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -207,6 +240,7 @@ GCC_PREFIX_HEADER = Scroller_Prefix.pch; INFOPLIST_FILE = "Scroller-Info.plist"; PRODUCT_NAME = Scroller; + TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -214,8 +248,10 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; "ARCHS[sdk=iphoneos*]" = armv7; "ARCHS[sdk=iphonesimulator*]" = i386; + CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; GCC_PREPROCESSOR_DEFINITIONS = DEBUG; @@ -230,8 +266,10 @@ C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; "ARCHS[sdk=iphoneos*]" = armv7; "ARCHS[sdk=iphonesimulator*]" = i386; + CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; GCC_WARN_ABOUT_RETURN_TYPE = YES; diff --git a/libs/Memory/Memory.h b/libs/Memory/Memory.h new file mode 100644 index 0000000..1b317ab --- /dev/null +++ b/libs/Memory/Memory.h @@ -0,0 +1,68 @@ +// +// Memory.h +// +// Created by Andrew Romanov on 30.12.09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface Memory : NSObject +{ + +} ++ (void)setRetain:(NSObject**)currObj newObj:(NSObject*)newObj; ++ (void)assignCurrObj:(NSObject**)currObj newObj:(NSObject*)newObj; ++ (void)releaseWithNil:(NSObject**)obj; +@end + + +#if ! __has_feature(objc_arc) +#define MAutorelease(__v) ([__v autorelease]) +#define MReturnAutoreleased(__v) ([__v autorelease]) + +#define MRetain(__v) ([__v retain]) +#define MReturnRetained MRetain + +#define MRelease(__v) ([__v release]) +#define MSafeRelease(__v) ([__v release], __v = nil) +#define MSuperDealloc ([super dealloc]) + +#define MWeak +#define MStrong + +#define MASSIGN_RETAIN(dst, src) [Memory setRetain:&dst newObj:src] +#define MRELEASE_NIL(obj) [Memory releaseWithNil:&obj] + +#define MStartAutoreleasePoll NSAutoreleasePool* _autoreleasePoolStarted = [[NSAutoreleasePool alloc] init]; +#define MEndAutoreleasePoll [_autoreleasePoolStarted drain]; + +#define MWeakProperty assign + +#else +// -fobjc-arc +#define MAutorelease(__v) +#define MReturnAutoreleased(__v) (__v) + +#define MRetain(__v) +#define MReturnRetained(__v) (__v) + +#define MRelease(__v) +#define MSafeRelease(__v) (__v = nil) +#define MSuperDealloc + +#define MWeak __weak +#define MStrong __strong + +#define MASSIGN_RETAIN(dst, src) (dst = src) +#define MRELEASE_NIL(obj) obj = nil + +#define MStartAutoreleasePoll @autoreleasepool { +#define MEndAutoreleasePoll } + +#define MWeakProperty strong + +#endif + + diff --git a/libs/Memory/Memory.m b/libs/Memory/Memory.m new file mode 100644 index 0000000..440bf22 --- /dev/null +++ b/libs/Memory/Memory.m @@ -0,0 +1,49 @@ +// +// Memory.h +// +// Created by Andrew Romanov on 30.12.09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import "Memory.h" + + +@implementation Memory +//---------------------------------------------------------- ++ (void)setRetain:(NSObject**)currObj newObj:(NSObject*)newObj +{ + if(*currObj != newObj) + { + if(*currObj) + { + MRelease(*currObj); + } + + *currObj = MReturnRetained(newObj); + } +} +//--------------------------------------------------------- ++ (void)releaseWithNil:(NSObject**)obj +{ + if(*obj) + { + MRelease(*obj); + *obj = nil; + } +} +//---------------------------------------------------------- ++ (void)assignCurrObj:(NSObject**)currObj newObj:(NSObject*)newObj +{ + if(*currObj != newObj) + { + #ifndef __OPTIMIZE__ + if((*currObj != nil) && (newObj == nil)) + { + NSLog(@"WARNING:assign nil object to not nil poiner"); + } + #endif + *currObj = newObj; + } +} + +@end diff --git a/main.m b/main.m index 08ae1c4..c582eca 100644 --- a/main.m +++ b/main.m @@ -22,11 +22,13 @@ // OR OTHER DEALINGS IN THE SOFTWARE. #import +#import "Memory.h" -int main(int argc, char *argv[]) { - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, @"ScrollerAppDelegate"); - [pool release]; - return retVal; +int main(int argc, char *argv[]) +{ + int retVal = 0; + MStartAutoreleasePoll + retVal = UIApplicationMain(argc, argv, nil, @"ScrollerAppDelegate"); + MEndAutoreleasePoll + return retVal; } From 1d6e1c2ed2fafc13fc0fc40e0daa5418494d0845 Mon Sep 17 00:00:00 2001 From: k-be Date: Fri, 7 Feb 2014 12:51:12 +0700 Subject: [PATCH 2/3] added to ignore some new files --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..18e3c60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ + +*.xcworkspacedata + +*.xcuserstate + +*.xcscheme + +*/xcschememanagement.plist + +Scroller.xcodeproj/xcuserdata/andrewromanov.xcuserdatad/xcschemes/xcschememanagement.plist From 6b9097e799983432e7ee9f63e348b529d65dba69 Mon Sep 17 00:00:00 2001 From: k-be Date: Tue, 11 Feb 2014 11:33:47 +0700 Subject: [PATCH 3/3] added check for responds selector --- Classes/HorizontalTableView.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Classes/HorizontalTableView.m b/Classes/HorizontalTableView.m index 8ba512e..42361fc 100644 --- a/Classes/HorizontalTableView.m +++ b/Classes/HorizontalTableView.m @@ -371,7 +371,10 @@ @implementation HorizontalTableView (Private) - (void)_removePages { [self.pageViews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [obj removeFromSuperview]; + if ([obj respondsToSelector:@selector(removeFromSuperview)]) + { + [obj removeFromSuperview]; + } }]; [self.pageViews removeAllObjects];