diff --git a/Classes/Popover/WEPopoverContainerView.h b/Classes/Popover/WEPopoverContainerView.h index ffe32a6..05d715a 100755 --- a/Classes/Popover/WEPopoverContainerView.h +++ b/Classes/Popover/WEPopoverContainerView.h @@ -28,11 +28,11 @@ CGFloat arrowMargin; } -@property(nonatomic, retain) NSString *bgImageName; -@property(nonatomic, retain) NSString *upArrowImageName; -@property(nonatomic, retain) NSString *downArrowImageName; -@property(nonatomic, retain) NSString *leftArrowImageName; -@property(nonatomic, retain) NSString *rightArrowImageName; +@property(nonatomic, strong) NSString *bgImageName; +@property(nonatomic, strong) NSString *upArrowImageName; +@property(nonatomic, strong) NSString *downArrowImageName; +@property(nonatomic, strong) NSString *leftArrowImageName; +@property(nonatomic, strong) NSString *rightArrowImageName; @property(nonatomic, assign) CGFloat leftBgMargin; @property(nonatomic, assign) CGFloat rightBgMargin; @property(nonatomic, assign) CGFloat topBgMargin; @@ -77,7 +77,7 @@ /** * @brief The content view being displayed. */ -@property (nonatomic, retain) UIView *contentView; +@property (nonatomic, strong) UIView *contentView; /** * @brief Initializes the position of the popover with a size, anchor rect, display area and permitted arrow directions and optionally the properties. diff --git a/Classes/Popover/WEPopoverContainerView.m b/Classes/Popover/WEPopoverContainerView.m index 1319c10..a42c3b2 100755 --- a/Classes/Popover/WEPopoverContainerView.m +++ b/Classes/Popover/WEPopoverContainerView.m @@ -13,14 +13,6 @@ @implementation WEPopoverContainerViewProperties @synthesize bgImageName, upArrowImageName, downArrowImageName, leftArrowImageName, rightArrowImageName, topBgMargin, bottomBgMargin, leftBgMargin, rightBgMargin, topBgCapSize, leftBgCapSize; @synthesize leftContentMargin, rightContentMargin, topContentMargin, bottomContentMargin, arrowMargin; -- (void)dealloc { - self.bgImageName = nil; - self.upArrowImageName = nil; - self.downArrowImageName = nil; - self.leftArrowImageName = nil; - self.rightArrowImageName = nil; - [super dealloc]; -} @end @@ -52,7 +44,7 @@ - (id)initWithSize:(CGSize)theSize [self initFrame]; self.backgroundColor = [UIColor clearColor]; UIImage *theImage = [UIImage imageNamed:properties.bgImageName]; - bgImage = [[theImage stretchableImageWithLeftCapWidth:properties.leftBgCapSize topCapHeight:properties.topBgCapSize] retain]; + bgImage = [theImage stretchableImageWithLeftCapWidth:properties.leftBgCapSize topCapHeight:properties.topBgCapSize]; self.clipsToBounds = YES; self.userInteractionEnabled = YES; @@ -60,13 +52,6 @@ - (id)initWithSize:(CGSize)theSize return self; } -- (void)dealloc { - [properties release]; - [contentView release]; - [bgImage release]; - [arrowImage release]; - [super dealloc]; -} - (void)drawRect:(CGRect)rect { [bgImage drawInRect:bgRect blendMode:kCGBlendModeNormal alpha:1.0]; @@ -108,8 +93,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - (void)setContentView:(UIView *)v { if (v != contentView) { - [contentView release]; - contentView = [v retain]; + contentView = v; contentView.frame = self.contentRect; [self addSubview:contentView]; } @@ -146,8 +130,7 @@ - (CGRect)contentRect { - (void)setProperties:(WEPopoverContainerViewProperties *)props { if (properties != props) { - [properties release]; - properties = [props retain]; + properties = props; } } @@ -348,16 +331,16 @@ - (void)determineGeometryForSize:(CGSize)theSize anchorRect:(CGRect)anchorRect d switch (arrowDirection) { case UIPopoverArrowDirectionUp: - arrowImage = [upArrowImage retain]; + arrowImage = upArrowImage; break; case UIPopoverArrowDirectionDown: - arrowImage = [downArrowImage retain]; + arrowImage = downArrowImage; break; case UIPopoverArrowDirectionLeft: - arrowImage = [leftArrowImage retain]; + arrowImage = leftArrowImage; break; case UIPopoverArrowDirectionRight: - arrowImage = [rightArrowImage retain]; + arrowImage = rightArrowImage; break; default: break; diff --git a/Classes/Popover/WEPopoverController.h b/Classes/Popover/WEPopoverController.h index 6261a87..e578a57 100755 --- a/Classes/Popover/WEPopoverController.h +++ b/Classes/Popover/WEPopoverController.h @@ -15,6 +15,8 @@ @protocol WEPopoverControllerDelegate +@optional + - (void)popoverControllerDidDismissPopover:(WEPopoverController *)popoverController; - (BOOL)popoverControllerShouldDismissPopover:(WEPopoverController *)popoverController; @@ -26,28 +28,28 @@ @interface WEPopoverController : NSObject { UIViewController *contentViewController; UIView *view; - UIView *parentView; + UIView __weak *parentView; WETouchableView *backgroundView; BOOL popoverVisible; UIPopoverArrowDirection popoverArrowDirection; - id delegate; + id __weak delegate; CGSize popoverContentSize; WEPopoverContainerViewProperties *containerViewProperties; id context; NSArray *passthroughViews; } -@property(nonatomic, retain) UIViewController *contentViewController; +@property(nonatomic, strong) UIViewController *contentViewController; -@property (nonatomic, readonly) UIView *view; +@property (nonatomic, strong, readonly) UIView *view; @property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible; @property (nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection; -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; @property (nonatomic, assign) CGSize popoverContentSize; -@property (nonatomic, retain) WEPopoverContainerViewProperties *containerViewProperties; -@property (nonatomic, retain) id context; -@property (nonatomic, assign) UIView *parentView; +@property (nonatomic, strong) WEPopoverContainerViewProperties *containerViewProperties; +@property (nonatomic, strong) id context; +@property (nonatomic, weak) UIView *parentView; @property (nonatomic, copy) NSArray *passthroughViews; - (id)initWithContentViewController:(UIViewController *)theContentViewController; diff --git a/Classes/Popover/WEPopoverController.m b/Classes/Popover/WEPopoverController.m index dabcc1a..7b02b9c 100755 --- a/Classes/Popover/WEPopoverController.m +++ b/Classes/Popover/WEPopoverController.m @@ -52,17 +52,11 @@ - (id)initWithContentViewController:(UIViewController *)viewController { - (void)dealloc { [self dismissPopoverAnimated:NO]; - [contentViewController release]; - [containerViewProperties release]; - [passthroughViews release]; - self.context = nil; - [super dealloc]; } - (void)setContentViewController:(UIViewController *)vc { if (vc != contentViewController) { - [contentViewController release]; - contentViewController = [vc retain]; + contentViewController = vc; popoverContentSize = CGSizeZero; } } @@ -73,7 +67,6 @@ - (BOOL)forwardAppearanceMethods { //Overridden setter to copy the passthroughViews to the background view if it exists already - (void)setPassthroughViews:(NSArray *)array { - [passthroughViews release]; passthroughViews = nil; if (array) { passthroughViews = [[NSArray alloc] initWithArray:array]; @@ -99,14 +92,16 @@ - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished c [self.view removeFromSuperview]; self.view = nil; [backgroundView removeFromSuperview]; - [backgroundView release]; backgroundView = nil; - BOOL userInitiatedDismissal = [(NSNumber *)theContext boolValue]; + BOOL userInitiatedDismissal = [(__bridge NSNumber *)theContext boolValue]; if (userInitiatedDismissal) { //Only send message to delegate in case the user initiated this event, which is if he touched outside the view - [delegate popoverControllerDidDismissPopover:self]; + if(delegate != nil && [delegate conformsToProtocol:@protocol(WEPopoverControllerDelegate)] && + [delegate respondsToSelector:@selector(popoverControllerDidDismissPopover:)]) { + [delegate popoverControllerDidDismissPopover:self]; + } } } } @@ -144,7 +139,7 @@ - (void)presentPopoverFromRect:(CGRect)rect CGRect displayArea = [self displayAreaForView:theView]; WEPopoverContainerViewProperties *props = self.containerViewProperties ? self.containerViewProperties : [self defaultContainerViewProperties]; - WEPopoverContainerView *containerView = [[[WEPopoverContainerView alloc] initWithSize:self.popoverContentSize anchorRect:rect displayArea:displayArea permittedArrowDirections:arrowDirections properties:props] autorelease]; + WEPopoverContainerView *containerView = [[WEPopoverContainerView alloc] initWithSize:self.popoverContentSize anchorRect:rect displayArea:displayArea permittedArrowDirections:arrowDirections properties:props]; popoverArrowDirection = containerView.arrowDirection; UIView *keyView = self.keyView; @@ -246,9 +241,13 @@ - (void)repositionPopoverFromRect:(CGRect)rect - (void)viewWasTouched:(WETouchableView *)view { if (popoverVisible) { - if (!delegate || [delegate popoverControllerShouldDismissPopover:self]) { - [self dismissPopoverAnimated:YES userInitiated:YES]; + BOOL shouldDismiss = YES; + if(delegate != nil && [delegate conformsToProtocol:@protocol(WEPopoverControllerDelegate)] && + [delegate respondsToSelector:@selector(popoverControllerShouldDismissPopover:)]) { + shouldDismiss = [delegate popoverControllerShouldDismissPopover:self]; } + if(shouldDismiss) + [self dismissPopoverAnimated:YES userInitiated:YES]; } } @@ -287,8 +286,7 @@ - (UIView *)keyView { - (void)setView:(UIView *)v { if (view != v) { - [view release]; - view = [v retain]; + view = v; } } @@ -316,7 +314,7 @@ - (void)dismissPopoverAnimated:(BOOL)animated userInitiated:(BOOL)userInitiated } completion:^(BOOL finished) { - [self animationDidStop:@"FadeOut" finished:[NSNumber numberWithBool:finished] context:[NSNumber numberWithBool:userInitiated]]; + [self animationDidStop:@"FadeOut" finished:[NSNumber numberWithBool:finished] context:(__bridge void *)([NSNumber numberWithBool:userInitiated])]; }]; @@ -327,7 +325,6 @@ - (void)dismissPopoverAnimated:(BOOL)animated userInitiated:(BOOL)userInitiated [self.view removeFromSuperview]; self.view = nil; [backgroundView removeFromSuperview]; - [backgroundView release]; backgroundView = nil; } } @@ -346,7 +343,7 @@ - (CGRect)displayAreaForView:(UIView *)theView { //Enable to use the simple popover style - (WEPopoverContainerViewProperties *)defaultContainerViewProperties { - WEPopoverContainerViewProperties *ret = [[WEPopoverContainerViewProperties new] autorelease]; + WEPopoverContainerViewProperties *ret = [WEPopoverContainerViewProperties new]; CGSize imageSize = CGSizeMake(30.0f, 30.0f); NSString *bgImageName = @"popoverBgSimple.png"; diff --git a/Classes/Popover/WETouchableView.h b/Classes/Popover/WETouchableView.h index 5210205..81ad89e 100644 --- a/Classes/Popover/WETouchableView.h +++ b/Classes/Popover/WETouchableView.h @@ -25,13 +25,13 @@ */ @interface WETouchableView : UIView { BOOL touchForwardingDisabled; - id delegate; + id __weak delegate; NSArray *passthroughViews; BOOL testHits; } @property (nonatomic, assign) BOOL touchForwardingDisabled; -@property (nonatomic, assign) id delegate; +@property (nonatomic, weak) id delegate; @property (nonatomic, copy) NSArray *passthroughViews; @end diff --git a/Classes/Popover/WETouchableView.m b/Classes/Popover/WETouchableView.m index e04fc9d..304ed39 100644 --- a/Classes/Popover/WETouchableView.m +++ b/Classes/Popover/WETouchableView.m @@ -18,10 +18,6 @@ @implementation WETouchableView @synthesize touchForwardingDisabled, delegate, passthroughViews; -- (void)dealloc { - [passthroughViews release]; - [super dealloc]; -} - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if (testHits) { diff --git a/Classes/WEPopoverAppDelegate.h b/Classes/WEPopoverAppDelegate.h index 46e41f1..a44d26c 100755 --- a/Classes/WEPopoverAppDelegate.h +++ b/Classes/WEPopoverAppDelegate.h @@ -15,8 +15,8 @@ UINavigationController *navController; } -@property (nonatomic, retain) IBOutlet UIWindow *window; -@property (nonatomic, retain) IBOutlet UINavigationController *navController; +@property (nonatomic, strong) IBOutlet UIWindow *window; +@property (nonatomic, strong) IBOutlet UINavigationController *navController; @end diff --git a/Classes/WEPopoverAppDelegate.m b/Classes/WEPopoverAppDelegate.m index 07bf4a4..0d3aa11 100755 --- a/Classes/WEPopoverAppDelegate.m +++ b/Classes/WEPopoverAppDelegate.m @@ -23,7 +23,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // Override point for customization after application launch. // Add the view controller's view to the window and display. - [window addSubview:navController.view]; + if([[[UIDevice currentDevice] systemVersion] floatValue] < 4.0) { + [window addSubview:navController.view]; + } else { + [window setRootViewController:navController]; + } [window makeKeyAndVisible]; return YES; @@ -78,11 +82,6 @@ Free up as much memory as possible by purging cached data objects that can be re } -- (void)dealloc { - [navController release]; - [window release]; - [super dealloc]; -} @end diff --git a/Classes/WEPopoverContentViewController.m b/Classes/WEPopoverContentViewController.m index f64829a..060c52a 100755 --- a/Classes/WEPopoverContentViewController.m +++ b/Classes/WEPopoverContentViewController.m @@ -86,7 +86,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]; } // Configure the cell... @@ -121,9 +121,6 @@ - (void)viewDidUnload { } -- (void)dealloc { - [super dealloc]; -} @end diff --git a/Classes/WEPopoverTableViewController.h b/Classes/WEPopoverTableViewController.h index c6d2d59..5cc4e47 100644 --- a/Classes/WEPopoverTableViewController.h +++ b/Classes/WEPopoverTableViewController.h @@ -15,7 +15,7 @@ Class popoverClass; } -@property (nonatomic, retain) WEPopoverController *popoverController; +@property (nonatomic, strong) WEPopoverController *popoverController; - (IBAction)showPopover:(id)sender; diff --git a/Classes/WEPopoverTableViewController.m b/Classes/WEPopoverTableViewController.m index 36e7421..6fb002a 100644 --- a/Classes/WEPopoverTableViewController.m +++ b/Classes/WEPopoverTableViewController.m @@ -103,7 +103,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]; } cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row]; @@ -156,7 +156,7 @@ - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *) */ - (WEPopoverContainerViewProperties *)improvedContainerViewProperties { - WEPopoverContainerViewProperties *props = [[WEPopoverContainerViewProperties alloc] autorelease]; + WEPopoverContainerViewProperties *props = [WEPopoverContainerViewProperties alloc]; NSString *bgImageName = nil; CGFloat bgMargin = 0.0; CGFloat bgCapSize = 0.0; @@ -210,7 +210,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath //CGRect rect = CGRectMake(frame.size.width * percentage, frame.origin.y, 1, frame.size.height); CGRect rect = frame; - self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease]; + self.popoverController = [[popoverClass alloc] initWithContentViewController:contentViewController]; if ([self.popoverController respondsToSelector:@selector(setContainerViewProperties:)]) { [self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]]; @@ -230,7 +230,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath animated:YES]; currentPopoverCellIndex = indexPath.row; - [contentViewController release]; } } @@ -243,7 +242,7 @@ - (IBAction)showPopover:(id)sender { if (!self.popoverController) { UIViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain]; - self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease]; + self.popoverController = [[popoverClass alloc] initWithContentViewController:contentViewController]; self.popoverController.delegate = self; self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar]; @@ -251,7 +250,6 @@ - (IBAction)showPopover:(id)sender { permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown) animated:YES]; - [contentViewController release]; } else { [self.popoverController dismissPopoverAnimated:YES]; self.popoverController = nil; @@ -282,9 +280,6 @@ - (void)didReceiveMemoryWarning { // Relinquish ownership any cached data, images, etc. that aren't in use. } -- (void)dealloc { - [super dealloc]; -} @end diff --git a/Classes/WEPopoverViewController.h b/Classes/WEPopoverViewController.h index 5061d95..122a081 100755 --- a/Classes/WEPopoverViewController.h +++ b/Classes/WEPopoverViewController.h @@ -14,7 +14,7 @@ WEPopoverController *popoverController; } -@property (nonatomic, retain) WEPopoverController *popoverController; +@property (nonatomic, strong) WEPopoverController *popoverController; - (IBAction)onButtonClick:(UIButton *)button; diff --git a/Classes/WEPopoverViewController.m b/Classes/WEPopoverViewController.m index eb4f4e5..9921ecd 100755 --- a/Classes/WEPopoverViewController.m +++ b/Classes/WEPopoverViewController.m @@ -70,19 +70,17 @@ - (IBAction)onButtonClick:(UIButton *)button { } else { UIViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain]; - self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:contentViewController] autorelease]; + self.popoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController]; [self.popoverController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; - [contentViewController release]; [button setTitle:@"Hide Popover" forState:UIControlStateNormal]; } } - (void)dealloc { [self viewDidUnload]; - [super dealloc]; } @end diff --git a/WEPopover.xcodeproj/project.pbxproj b/WEPopover.xcodeproj/project.pbxproj index f059514..182362e 100755 --- a/WEPopover.xcodeproj/project.pbxproj +++ b/WEPopover.xcodeproj/project.pbxproj @@ -314,6 +314,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -328,6 +329,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 = WEPopover_Prefix.pch; diff --git a/main.m b/main.m index b0ac185..9994bf6 100755 --- a/main.m +++ b/main.m @@ -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; + } }