Skip to content

Commit

Permalink
Added presentPopoverFromBarButtonItem method as specified by the UIPo…
Browse files Browse the repository at this point in the history
…poverController contract.
  • Loading branch information
Werner Altewischer committed May 6, 2011
1 parent bc788ff commit d56c929
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 60 deletions.
4 changes: 2 additions & 2 deletions Classes/WEPopoverAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

@interface WEPopoverAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
WEPopoverViewController *viewController;
UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet WEPopoverViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@end

6 changes: 3 additions & 3 deletions Classes/WEPopoverAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@implementation WEPopoverAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize navController;


#pragma mark -
Expand All @@ -23,7 +23,7 @@ - (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:viewController.view];
[window addSubview:navController.view];
[window makeKeyAndVisible];

return YES;
Expand Down Expand Up @@ -79,7 +79,7 @@ Free up as much memory as possible by purging cached data objects that can be re


- (void)dealloc {
[viewController release];
[navController release];
[window release];
[super dealloc];
}
Expand Down
4 changes: 4 additions & 0 deletions Classes/WEPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@

- (void)dismissPopoverAnimated:(BOOL)animated;

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;

- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
Expand Down
13 changes: 13 additions & 0 deletions Classes/WEPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "WEPopoverController.h"
#import "WEPopoverParentView.h"
#import "UIBarButtonItem+WEPopover.h"

#define FADE_DURATION 0.25

Expand Down Expand Up @@ -102,6 +103,18 @@ - (void)dismissPopoverAnimated:(BOOL)animated {
[self dismissPopoverAnimated:animated userInitiated:NO];
}

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated {


UIView *v = [[UIApplication sharedApplication] keyWindow];

CGRect rect = [item frameInView:v];

return [self presentPopoverFromRect:rect inView:v permittedArrowDirections:arrowDirections animated:animated];
}

- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)theView
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
Expand Down
2 changes: 2 additions & 0 deletions Classes/WEPopoverTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

@property (nonatomic, retain) WEPopoverController *popoverController;

- (IBAction)showPopover:(id)sender;

@end
21 changes: 21 additions & 0 deletions Classes/WEPopoverTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

}

#pragma mark -
#pragma mark Actions

- (IBAction)showPopover:(id)sender {

if (!self.popoverController) {
UIViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:contentViewController] autorelease];
self.popoverController.delegate = self;
self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];

[self.popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown
animated:YES];
[contentViewController release];
} else {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
}

#pragma mark -
#pragma mark WEPopoverControllerDelegate implementation

Expand Down
Loading

0 comments on commit d56c929

Please sign in to comment.