English 中文(简体)
3. 发现居民遗弃
原标题:Detecting of popover dismiss

I wanted to play with UIPopupController, and I understood that I can t detect when my popover dismiss. My steps:
1. Create example from XCode (File -> New Project - > Utilitiy Application)
2. Add to MainViewController.h UIPopoverControllerDelegate

#import "FlipsideViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UIPopoverControllerDelegate>

@property (strong, nonatomic) UIPopoverController *flipsidePopoverController;

- (IBAction)showInfo:(id)sender;

@end
  1. In MainViewController:

    - (IBAction)showInfo:(id)sender
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
            controller.delegate = self;
            controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentModalViewController:controller animated:YES];
        } else {
            if (!self.flipsidePopoverController) {
                FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
                controller.delegate = self;

                self.flipsidePopoverController.delegate = self

                self.flipsidePopoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
            }
            if ([self.flipsidePopoverController isPopoverVisible]) {
                [self.flipsidePopoverController dismissPopoverAnimated:YES];
            } else {
                [self.flipsidePopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            }
        }
    }

    -(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    {
        NSLog(@"OLOLO");
    }

But when I tap somewhere, and popover disappears, there is no NSLog message in Console. What am I doing wrong?

问题回答

安排居民代表自食其力,也可以使用两名人口代表,即:

 /* Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the dismissal of the view.
 */
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController;

/* Called on the delegate when the user has taken action to dismiss the popover. This is not called when -dismissPopoverAnimated: is called directly.
 */
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController;

较早的答复建议使用UIPopoverControllerDelegate,看来这是实现这一目标的唯一明智途径。 我认为,添加一个实际例子是有益的,因为它不是你头盔最简单的事情。 我的要求很简单,我希望背景看法模糊不清,而人口则明显。

  1. 在一个故事板上监控你的人数,使该片在目的地观测控制器属性中散布内容。

  2. 3. 您的消息来源认为控制者是UIPopover 主计长 代表:

    @interface MyController : UIViewController <UIPopoverControllerDelegate>
    
  3. 2. 过度准备 ForSegue, 指派你的消息来源认为控制者为人口代表,然后在排泄之前将甲状腺确定为0.5:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
        popover.popoverController.delegate = self;
        self.view.alpha = 0.5;
    }
    
  4. 采用人口代表法 主计长 DidDismissPopover。 将甲型六氯环己烷带回1.0,不辞去自己作为代表,以确保我们不要停止阿农发委的工作:

    -(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
        self.view.alpha = 1.0;
        popoverController.delegate = nil;
    }
    

您是否将主审法官定为人民代表?

(if you create the popover through code) popover.delegate = self;

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIStoryboardPopoverSegue *popoverSegue;
popoverSegue = (UIStoryboardPopoverSegue *)segue;
popoverController = popoverSegue.popoverController;
pCVisible = YES;
[[segue destinationViewController] setDelegate:self];
}

- (void) setDataFromPopover {
  if (pCVisible) {
     [popoverController dismissPopoverAnimated:YES]; // THIS IS KEY!   this is where the popover is dismissed, not in the popover itself
  }
}

并且

//TableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:       (NSIndexPath *)indexPath
{
   //variable = whatever

OtherViewController *initialView;
initialView=(OtherViewController *)self.delegate;
initialView.theLabel.text = variable;
[initialView setDataFromPopover];
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签