Skip to content

Commit

Permalink
ARC support
Browse files Browse the repository at this point in the history
  • Loading branch information
honcheng committed Aug 21, 2012
1 parent f9700ea commit 8a2ebb7
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -4,3 +4,5 @@ blog-resources/paneltableview-demo.mov
PanelTableView/PanelTableView.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/UserInterfaceState.xcuserstate
PanelTableView/PanelTableView.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/PanelTableView.xcscheme
PanelTableView/PanelTableView.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/xcschememanagement.plist
sample project/SampleApp/SampleApp.xcodeproj/project.xcworkspace/xcuserdata/honcheng.xcuserdatad/UserInterfaceState.xcuserstate
sample project/SampleApp/SampleApp.xcodeproj/xcuserdata/honcheng.xcuserdatad/xcschemes/SampleApp.xcscheme
4 changes: 2 additions & 2 deletions PanelTableView/Classes/PanelIndexPath.m
Expand Up @@ -50,12 +50,12 @@ - (id)initWithRow:(int)_row section:(int)_section page:(int)_page

+ (id)panelIndexPathForRow:(int)_row section:(int)_section page:(int)_page
{
return [[[self alloc] initWithRow:_row section:_section page:_page] autorelease];
return [[self alloc] initWithRow:_row section:_section page:_page];
}

+ (id)panelIndexPathForPage:(int)_page indexPath:(NSIndexPath*)indexPath
{
return [[[self alloc] initWithRow:indexPath.row section:indexPath.section page:_page] autorelease];
return [[self alloc] initWithRow:indexPath.row section:indexPath.section page:_page];
}

@end
11 changes: 5 additions & 6 deletions PanelTableView/Classes/PanelView.h
Expand Up @@ -35,27 +35,26 @@
#import "PanelIndexPath.h"
#import <QuartzCore/QuartzCore.h>

@protocol PanelViewDelegate
@protocol PanelViewDelegate <NSObject>
- (NSInteger)panelView:(id)panelView numberOfRowsInPage:(NSInteger)page section:(NSInteger)section;
- (UITableViewCell *)panelView:(id)panelView cellForRowAtIndexPath:(PanelIndexPath *)indexPath;
- (void)panelView:(id)panelView didSelectRowAtIndexPath:(PanelIndexPath *)indexPath;
- (CGFloat)panelView:(id)panelView heightForRowAtIndexPath:(PanelIndexPath *)indexPath;
- (BOOL)respondsToSelector:(SEL)selector;
- (NSInteger)panelView:(id)panelView numberOfSectionsInPage:(NSInteger)pageNumber;
- (NSString*)panelView:(id)panelView titleForHeaderInPage:(NSInteger)pageNumber section:(NSInteger)section;
@end

@interface PanelView : UIView <UITableViewDelegate, UITableViewDataSource>{
int pageNumber;
UITableView *tableView;
id<PanelViewDelegate> delegate;
id<PanelViewDelegate> __unsafe_unretained delegate;
NSString *identifier;
}

@property (nonatomic, assign) int pageNumber;
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, assign) id<PanelViewDelegate> delegate;
@property (nonatomic, retain) NSString *identifier;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, unsafe_unretained) id<PanelViewDelegate> delegate;
@property (nonatomic, strong) NSString *identifier;

- (id)initWithIdentifier:(NSString*)_identifier;
- (void)reset;
Expand Down
8 changes: 0 additions & 8 deletions PanelTableView/Classes/PanelView.m
Expand Up @@ -51,7 +51,6 @@ - (id)initWithFrame:(CGRect)frame

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,frame.size.width,frame.size.height)];
[self addSubview:self.tableView];
[self.tableView release];
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
}
Expand Down Expand Up @@ -103,13 +102,6 @@ - (void)pageWillDisappear
[self saveTableviewOffset];
}

- (void)dealloc
{
[self.identifier release];
[self.tableView release];
[super dealloc];
}

#pragma mark offset save/restore

#define kTableOffset @"kTableOffset"
Expand Down
4 changes: 2 additions & 2 deletions PanelTableView/Classes/PanelsViewController.h
Expand Up @@ -52,8 +52,8 @@
BOOL _isEditing;
}

@property (nonatomic, retain) UIScrollViewExt *scrollView;
@property (nonatomic, retain) NSMutableSet *recycledPages, *visiblePages;
@property (nonatomic, strong) UIScrollViewExt *scrollView;
@property (nonatomic, strong) NSMutableSet *recycledPages, *visiblePages;

#define GAP 10
#define TAG_PAGE 11000
Expand Down
37 changes: 11 additions & 26 deletions PanelTableView/Classes/PanelsViewController.m
Expand Up @@ -51,7 +51,6 @@ - (PanelView *)panelForPage:(NSInteger)page;
@end

@implementation PanelsViewController
@synthesize scrollView;
@synthesize recycledPages, visiblePages;

- (void)loadView
Expand All @@ -60,17 +59,16 @@ - (void)loadView
[self.view setBackgroundColor:[UIColor blackColor]];

CGRect frame = [self scrollViewFrame];
self.scrollView = [[UIScrollViewExt alloc] initWithFrame:CGRectMake(-1*GAP,0,frame.size.width+2*GAP,frame.size.height)];
[self.scrollView setDelegate:self];
[self.scrollView setShowsHorizontalScrollIndicator:NO];
[self.scrollView setPagingEnabled:YES];
[self.scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
_scrollView = [[UIScrollViewExt alloc] initWithFrame:CGRectMake(-1*GAP,0,frame.size.width+2*GAP,frame.size.height)];
[_scrollView setDelegate:self];
[_scrollView setShowsHorizontalScrollIndicator:NO];
[_scrollView setPagingEnabled:YES];
[_scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.view addSubview:self.scrollView];
[self.scrollView release];
[self.scrollView setContentSize:CGSizeMake(([self panelViewSize].width+2*GAP)*[self numberOfPanels],self.scrollView.frame.size.height)];
[_scrollView setContentSize:CGSizeMake(([self panelViewSize].width+2*GAP)*[self numberOfPanels],_scrollView.frame.size.height)];

self.recycledPages = [NSMutableSet new];
self.visiblePages = [NSMutableSet new];
self.recycledPages = [NSMutableSet set];
self.visiblePages = [NSMutableSet set];

[self tilePages];
}
Expand All @@ -89,14 +87,6 @@ - (void)viewDidUnload {
// e.g. self.myOutlet = nil;
}

- (void)dealloc
{
[self.scrollView release];
[self.recycledPages release];
[self.visiblePages release];
[super dealloc];
}

- (void)viewDidAppear:(BOOL)animated
{
PanelView *panelView = [self panelViewAtPage:currentPage];
Expand Down Expand Up @@ -352,7 +342,7 @@ - (PanelView*)dequeueReusablePageWithIdentifier:(NSString*)identifier
PanelView *page = [filteredSet anyObject];
if (page)
{
[[page retain] autorelease];
//[[page retain] autorelease];
[self.recycledPages removeObject:page];
}
return page;
Expand All @@ -372,7 +362,7 @@ - (PanelView *)panelForPage:(NSInteger)page
PanelView *panelView = (PanelView*)[self dequeueReusablePageWithIdentifier:identifier];
if (panelView == nil)
{
panelView = [[[PanelView alloc] initWithIdentifier:identifier] autorelease];
panelView = [[PanelView alloc] initWithIdentifier:identifier];
}
return panelView;
}
Expand All @@ -393,7 +383,7 @@ - (UITableViewCell *)panelView:(PanelView *)panelView cellForRowAtIndexPath:(Pan
UITableViewCell *cell = (UITableViewCell*)[panelView.tableView dequeueReusableCellWithIdentifier:identity];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];
}
return cell;
}
Expand All @@ -418,10 +408,5 @@ - (NSString*)panelView:(id)panelView titleForHeaderInPage:(NSInteger)pageNumber
return [NSString stringWithFormat:@"Page %i Section %i", pageNumber, section];
}

- (BOOL)respondsToSelector:(SEL)aSelector
{
return [super respondsToSelector:aSelector];
}


@end
2 changes: 1 addition & 1 deletion sample project/SampleApp/Classes/SampleAppAppDelegate.h
Expand Up @@ -12,7 +12,7 @@
UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, strong) IBOutlet UIWindow *window;



Expand Down
6 changes: 1 addition & 5 deletions sample project/SampleApp/Classes/SampleAppAppDelegate.m
Expand Up @@ -31,7 +31,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:panelsViewController];
[[navController navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
[window addSubview:navController.view];
[window setRootViewController:navController];

[self.window makeKeyAndVisible];

Expand Down Expand Up @@ -87,10 +87,6 @@ Free up as much memory as possible by purging cached data objects that can be re
}


- (void)dealloc {
[window release];
[super dealloc];
}


@end
3 changes: 0 additions & 3 deletions sample project/SampleApp/Classes/SamplePanelView.m
Expand Up @@ -22,9 +22,6 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}

- (void)dealloc {
[super dealloc];
}


@end
Expand Up @@ -14,7 +14,7 @@
UIBarButtonItem *editItem, *doneItem, *addRemoveItem;
}

@property (nonatomic, retain) NSMutableArray *panelsArray;
@property (nonatomic, strong) NSMutableArray *panelsArray;

- (void)addTemporaryUI;

Expand Down
11 changes: 2 additions & 9 deletions sample project/SampleApp/Classes/SamplePanelsViewController.m
Expand Up @@ -48,12 +48,6 @@ - (void)viewDidUnload {
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[self.panelsArray release];
[super dealloc];
}

#pragma mark temporary

// this method is used to insert add/delete button to show the demonstrate the add/delete function
Expand All @@ -68,7 +62,6 @@ - (void)addTemporaryUI
[segmentControl setMomentary:YES];
[segmentControl setSegmentedControlStyle:UISegmentedControlStyleBar];
addRemoveItem = [[UIBarButtonItem alloc] initWithCustomView:segmentControl];
[segmentControl release];
[self.navigationItem setLeftBarButtonItem:addRemoveItem];
[segmentControl addTarget:self action:@selector(onSegmentControlValueChanged:) forControlEvents:UIControlEventValueChanged];

Expand Down Expand Up @@ -144,7 +137,7 @@ - (UITableViewCell *)panelView:(PanelView *)panelView cellForRowAtIndexPath:(Pan
UITableViewCell *cell = (UITableViewCell*)[panelView.tableView dequeueReusableCellWithIdentifier:identity];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];
}
[[cell textLabel] setText:[NSString stringWithFormat:@"panel %i section %i row %i", indexPath.page, indexPath.section, indexPath.row+1]];
return cell;
Expand Down Expand Up @@ -174,7 +167,7 @@ - (PanelView *)panelForPage:(NSInteger)page
SamplePanelView *panelView = (SamplePanelView*)[self dequeueReusablePageWithIdentifier:identifier];
if (panelView == nil)
{
panelView = [[[SamplePanelView alloc] initWithIdentifier:identifier] autorelease];
panelView = [[SamplePanelView alloc] initWithIdentifier:identifier];
}
return panelView;
}
Expand Down
Expand Up @@ -44,9 +44,6 @@ - (void)viewDidUnload {
}


- (void)dealloc {
[super dealloc];
}


@end
4 changes: 4 additions & 0 deletions sample project/SampleApp/SampleApp.xcodeproj/project.pbxproj
Expand Up @@ -228,12 +228,14 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SampleApp_Prefix.pch;
INFOPLIST_FILE = "SampleApp-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = SampleApp;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -245,10 +247,12 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SampleApp_Prefix.pch;
INFOPLIST_FILE = "SampleApp-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = SampleApp;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
8 changes: 4 additions & 4 deletions sample project/SampleApp/main.m
Expand Up @@ -10,8 +10,8 @@

int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, nil);
return retVal;
}
}

0 comments on commit 8a2ebb7

Please sign in to comment.