Skip to content

Commit

Permalink
Convert to ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
dfabulich committed May 5, 2012
1 parent 87c91b5 commit c8fa239
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 42 deletions.
14 changes: 7 additions & 7 deletions SBTableAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ typedef enum {

@interface SBTableAlert : NSObject <UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate> {}

@property (nonatomic, retain) UIAlertView *view;
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic) UIAlertView *view;
@property (nonatomic) UITableView *tableView;
@property (nonatomic) SBTableAlertType type;
@property (nonatomic) SBTableAlertStyle style;
@property (nonatomic) NSInteger maximumVisibleRows; // default 4, (nice in both orientations w/ rowHeigh == 40), if -1 is passed it will display the whole table.
@property (nonatomic) CGFloat rowHeight; // default 40, (default in UITableView == 44)

@property (nonatomic, assign) id <SBTableAlertDelegate> delegate;
@property (nonatomic, assign) id <SBTableAlertDataSource> dataSource;
@property (nonatomic, unsafe_unretained) id <SBTableAlertDelegate> delegate;
@property (nonatomic, unsafe_unretained) id <SBTableAlertDataSource> dataSource;

@property (nonatomic, assign) id <UITableViewDelegate> tableViewDelegate; // default self, (set other for more advanded use)
@property (nonatomic, assign) id <UITableViewDataSource> tableViewDataSource; // default self, (set other for more advanded use)
@property (nonatomic, assign) id <UIAlertViewDelegate> alertViewDelegate; // default self, (set other for more advanded use)
@property (nonatomic, unsafe_unretained) id <UITableViewDelegate> tableViewDelegate; // default self, (set other for more advanded use)
@property (nonatomic, unsafe_unretained) id <UITableViewDataSource> tableViewDataSource; // default self, (set other for more advanded use)
@property (nonatomic, unsafe_unretained) id <UIAlertViewDelegate> alertViewDelegate; // default self, (set other for more advanded use)

- (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle messageFormat:(NSString *)message, ...;
+ (id)alertWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle messageFormat:(NSString *)message, ...;
Expand Down
20 changes: 5 additions & 15 deletions SBTableAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ - (id)initWithTitle:(NSString *)title {
return self;
}

- (void)dealloc {
[self setTitle:nil];
[super dealloc];
}

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
Expand Down Expand Up @@ -148,7 +144,7 @@ - (void)drawRect:(CGRect)rect {
@end

@interface SBTableAlertCell ()
@property (nonatomic, retain) SBTableAlertCellBackgroundView *cellBackgroundView;
@property (nonatomic) SBTableAlertCellBackgroundView *cellBackgroundView;
@end

@implementation SBTableAlertCell
Expand All @@ -162,7 +158,6 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
[_cellBackgroundView setBackgroundColor:[UIColor clearColor]];
[_cellBackgroundView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[self setBackgroundView:_cellBackgroundView];
[_cellBackgroundView release];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setNeedsDisplay) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}
Expand All @@ -171,7 +166,6 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

- (void)layoutSubviews {
Expand Down Expand Up @@ -216,7 +210,7 @@ - (void)drawCellBackgroundView:(CGRect)r {
@end

@interface SBTableAlert ()
@property (nonatomic, retain) SBTableViewTopShadowView *shadow;
@property (nonatomic) SBTableViewTopShadowView *shadow;
@property (nonatomic, assign) BOOL presented;

- (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle messageFormat:(NSString *)format args:(va_list)args;
Expand Down Expand Up @@ -246,7 +240,7 @@ @implementation SBTableAlert

- (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle messageFormat:(NSString *)format args:(va_list)args {
if ((self = [super init])) {
NSString *message = format ? [[[NSString alloc] initWithFormat:format arguments:args] autorelease] : nil;
NSString *message = format ? [[NSString alloc] initWithFormat:format arguments:args] : nil;

_alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:nil];

Expand Down Expand Up @@ -288,18 +282,14 @@ - (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle
}

+ (id)alertWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelTitle messageFormat:(NSString *)message, ... {
return [[[SBTableAlert alloc] initWithTitle:title cancelButtonTitle:cancelTitle messageFormat:message] autorelease];
return [[SBTableAlert alloc] initWithTitle:title cancelButtonTitle:cancelTitle messageFormat:message];
}

- (void)dealloc {
[self setTableView:nil];
[self setView:nil];

[self setShadow:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self];

[super dealloc];
}

#pragma mark -
Expand Down Expand Up @@ -436,7 +426,7 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
if (!title)
return nil;

return [[[SBTableViewSectionHeaderView alloc] initWithTitle:title] autorelease];
return [[SBTableViewSectionHeaderView alloc] initWithTitle:title];
}

return nil;
Expand Down
2 changes: 2 additions & 0 deletions SBTableAlertDemo/SBTableAlertDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand All @@ -258,6 +259,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SBTableAlertDemo/SBTableAlertDemo-Prefix.pch";
Expand Down
11 changes: 3 additions & 8 deletions SBTableAlertDemo/SBTableAlertDemo/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

if ([indexPath row] == 1)
[cell.textLabel setText:@"Single Select"];
Expand Down Expand Up @@ -113,21 +113,17 @@ - (void)viewDidUnload
// For example: self.myOutlet = nil;
}

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

#pragma mark - SBTableAlertDataSource

- (UITableViewCell *)tableAlert:(SBTableAlert *)tableAlert cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;

if (tableAlert.view.tag == 0 || tableAlert.view.tag == 1) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
} else {
// Note: SBTableAlertCell
cell = [[[SBTableAlertCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell = [[SBTableAlertCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}

[cell.textLabel setText:[NSString stringWithFormat:@"Cell %d", indexPath.row]];
Expand Down Expand Up @@ -173,7 +169,6 @@ - (void)tableAlert:(SBTableAlert *)tableAlert didSelectRowAtIndexPath:(NSIndexPa
- (void)tableAlert:(SBTableAlert *)tableAlert didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"Dismissed: %i", buttonIndex);

[tableAlert release];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

}

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

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic) IBOutlet UINavigationController *navigationController;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,5 @@ - (void)applicationWillTerminate:(UIApplication *)application
*/
}

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

@end
8 changes: 4 additions & 4 deletions SBTableAlertDemo/SBTableAlertDemo/main.m
Original file line number Diff line number Diff line change
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 c8fa239

Please sign in to comment.