forked from mruegenberg/objc-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcel Ruegenberg
committed
Jun 4, 2011
1 parent
121461b
commit 22dd89e
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
// | |||
// SynthesizeSingleton.h | |||
// CocoaWithLove | |||
// | |||
// Created by Matt Gallagher on 20/10/08. | |||
// Copyright 2009 Matt Gallagher. All rights reserved. | |||
// | |||
// Permission is given to use this source code file without charge in any | |||
// project, commercial or otherwise, entirely at your risk, with the condition | |||
// that any redistribution (in part or whole) of source code must retain | |||
// this copyright and permission notice. Attribution in compiled projects is | |||
// appreciated but not required. | |||
// | |||
|
|||
#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \ | |||
\ | |||
static classname *shared##classname = nil; \ | |||
\ | |||
+ (classname *)shared##classname \ | |||
{ \ | |||
@synchronized(self) \ | |||
{ \ | |||
if (shared##classname == nil) \ | |||
{ \ | |||
shared##classname = [[self alloc] init]; \ | |||
} \ | |||
} \ | |||
\ | |||
return shared##classname; \ | |||
} \ | |||
\ | |||
+ (id)allocWithZone:(NSZone *)zone \ | |||
{ \ | |||
@synchronized(self) \ | |||
{ \ | |||
if (shared##classname == nil) \ | |||
{ \ | |||
shared##classname = [super allocWithZone:zone]; \ | |||
return shared##classname; \ | |||
} \ | |||
} \ | |||
\ | |||
return nil; \ | |||
} \ | |||
\ | |||
- (id)copyWithZone:(NSZone *)zone \ | |||
{ \ | |||
return self; \ | |||
} \ | |||
\ | |||
- (id)retain \ | |||
{ \ | |||
return self; \ | |||
} \ | |||
\ | |||
- (NSUInteger)retainCount \ | |||
{ \ | |||
return NSUIntegerMax; \ | |||
} \ | |||
\ | |||
- (void)release \ | |||
{ \ | |||
} \ | |||
\ | |||
- (id)autorelease \ | |||
{ \ | |||
return self; \ | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
// | |||
// PopoverManager.h | |||
// Lists | |||
// | |||
// Created by Marcel Ruegenberg on 25.02.11. | |||
// Copyright 2011 Dustlab. All rights reserved. | |||
// | |||
|
|||
#import <Foundation/Foundation.h> | |||
|
|||
/** | |||
A class for managing the retaining of popovers in a central place. | |||
Because even though Apple basically tells you to have only one popover at a time, they make it surprisingly hard to do this properly. | |||
*/ | |||
@interface PopoverManager : NSObject { | |||
UIPopoverController *currentPopoverController; | |||
} | |||
|
|||
@property (nonatomic, retain) UIPopoverController *currentPopoverController; | |||
|
|||
+ (PopoverManager *)sharedPopoverManager; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
// | |||
// PopoverManager.m | |||
// Lists | |||
// | |||
// Created by Marcel Ruegenberg on 25.02.11. | |||
// Copyright 2011 Dustlab. All rights reserved. | |||
// | |||
|
|||
#import "PopoverManager.h" | |||
#import "SynthesizeSingleton.h" | |||
|
|||
@implementation PopoverManager | |||
@synthesize currentPopoverController; | |||
|
|||
SYNTHESIZE_SINGLETON_FOR_CLASS(PopoverManager); | |||
|
|||
- (id)init { | |||
if((self = [super init])) { | |||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; | |||
} | |||
return self; | |||
} | |||
|
|||
- (void)setCurrentPopoverController:(UIPopoverController *)thePopoverController { | |||
if(thePopoverController != currentPopoverController) { | |||
if(currentPopoverController && currentPopoverController.popoverVisible) { | |||
#ifndef NDEBUG | |||
NSLog(@"Warning: New popover being set in PopoverManager while existing popover is still visible."); | |||
#endif | |||
[currentPopoverController dismissPopoverAnimated:NO]; // no animation when dismissing because this should not happen | |||
} | |||
[currentPopoverController release]; | |||
currentPopoverController = [thePopoverController retain]; | |||
} | |||
} | |||
|
|||
- (void)didReceiveMemoryWarning:(NSNotification *)notification { | |||
if(self.currentPopoverController && ! self.currentPopoverController.popoverVisible) { | |||
self.currentPopoverController = nil; | |||
} | |||
} | |||
|
|||
- (void) dealloc | |||
{ | |||
self.currentPopoverController = nil; | |||
[super dealloc]; | |||
} | |||
|
|||
|
|||
@end |