mingsai

Managing multiple Popover (PostViewController.m)

Sep 9th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  PostViewController.m
  3. //  Berry
  4. //
  5. //  Created by Tommie Carter on 9/8/12.
  6. //  Copyright (c) 2012 Tommie Carter. All rights reserved.
  7. //
  8.  
  9. #import "PostViewController.h"
  10.  
  11. @interface PostViewController ()
  12.  
  13. @end
  14.  
  15. @implementation PostViewController
  16. @synthesize  popoverContent, popViewController;
  17.  
  18. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  19. {
  20.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21.     if (self) {
  22.         // Custom initialization
  23.     }
  24.     return self;
  25. }
  26.  
  27. - (void)viewDidLoad
  28. {
  29.     [super viewDidLoad];
  30.     [[NSNotificationCenter defaultCenter]
  31.      addObserver:self
  32.      selector:@selector(willEnterForegroundNotification:)
  33.      name:UIApplicationWillEnterForegroundNotification
  34.      object:nil];
  35.    
  36.     [[NSNotificationCenter defaultCenter]
  37.      addObserver:self
  38.      selector:@selector(willResignActiveNotification:)
  39.      name:UIApplicationWillResignActiveNotification
  40.      object:nil];
  41.    
  42.     // Do any additional setup after loading the view.
  43. }
  44. - (void)willEnterForegroundNotification:(NSNotification *)notification
  45. {
  46.     //
  47. }
  48.  
  49. - (void)willResignActiveNotification:(NSNotification *)notification
  50. {
  51.     [self setPopoverContent:nil];
  52. }
  53.  
  54. -(void)didReceiveMemoryWarning{
  55.     [super didReceiveMemoryWarning];
  56.     //release stuff
  57. }
  58.  
  59. - (void)viewDidUnload
  60. {
  61.     [self setPopoverContent:nil];
  62.     [super viewDidUnload];
  63.     // Release any retained subviews of the main view.
  64. }
  65. - (void)viewWillAppear:(BOOL)animated{
  66.  
  67. }
  68. - (void)viewDidAppear:(BOOL)animated{
  69.  
  70. }
  71. - (void)viewWillDisappear:(BOOL)animated{
  72.  
  73. }
  74. - (void)viewDidDisappear:(BOOL)animated{
  75.  
  76. }
  77. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  78. {
  79.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  80. }
  81.  
  82.  
  83. /* Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the dismissal of the view.
  84.  */
  85. - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
  86.     return YES;
  87. }
  88.  
  89. /* Called on the delegate when the user has taken action to dismiss the popover. This is not called when -dismissPopoverAnimated: is called directly.
  90.  */
  91. - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{
  92.    
  93. }
  94.  
  95. - (IBAction)showPopContentView:(id)sender {
  96.    
  97.     UIButton *popContentButton = (UIButton*)sender;
  98.  
  99.     if (![self popoverContent])
  100.     {
  101.         switch (popContentButton.tag) {
  102.             case 100:
  103.                 popoverContent = (ClientViewController*)[[self storyboard]instantiateViewControllerWithIdentifier:@"ClientViewController"];
  104.                 break;
  105.             case 101:
  106.                 popoverContent = (MatterViewController*)[[self storyboard]instantiateViewControllerWithIdentifier:@"MatterViewController"];
  107.                 break;
  108.             case 102:
  109.                 popoverContent = (ActivityViewController*)[[self storyboard]instantiateViewControllerWithIdentifier:@"ActivityViewController"];
  110.                 break;
  111.             case 103:
  112.                 popoverContent = (TaskViewController*)[[self storyboard]instantiateViewControllerWithIdentifier:@"TaskViewController"];
  113.                 break;
  114.             default:
  115.                 NSLog(@"%s ; BAD POPOVER BUTTON POINTER",__PRETTY_FUNCTION__);
  116.                 break;
  117.         }
  118.      
  119.         popoverContent.contentSizeForViewInPopover = CGSizeMake(320.0,299.0);
  120.        
  121.         //popViewController is also a property
  122.         popViewController = [[UIPopoverController alloc]
  123.                              initWithContentViewController:popoverContent];
  124.        
  125.     }
  126.                                
  127.     // Perform setup on the fancy controller you want to do every
  128.     // time the action gets triggered here. Do initialization in the if
  129.     // block above.
  130.                                
  131.     // Now display the popover from the sender's frame.
  132.     [popViewController presentPopoverFromRect:popContentButton.frame
  133.                                        inView:[self view]
  134.                      permittedArrowDirections:UIPopoverArrowDirectionAny
  135.                                      animated:YES];
  136.    
  137.     popoverContent = nil;
  138.     popContentButton = nil;
  139.  
  140.  
  141. }
  142. @end
Advertisement
Add Comment
Please, Sign In to add comment