【问题标题】:dismiss UIPopOverController from contentViewController从 contentViewController 中关闭 UIPopOverController
【发布时间】:2011-09-08 10:59:45
【问题描述】:

如何从 contentViewController 中关闭弹出框,因此在下面的示例代码中,我想从 ProfileViewController 代码中关闭 UIPopOver。我该怎么做呢?另一个类似的帖子建议使用NSNotification,但是如何使用呢?

- (void)profilePop:(UITapGestureRecognizer *)recognizer
{
    ProfileViewController * profile = [[ProfileViewController alloc] init];
    CGPoint location = [recognizer locationInView:self.table];
    NSIndexPath* indexPath = [self.table indexPathForRowAtPoint:location];
    ConvoreCell* cell = (ConvoreCell *) [self.table cellForRowAtIndexPath:indexPath];
    profile.uid =  [[[self.posts objectAtIndex:indexPath.row] creator] mid];
    UIPopoverController * profilePop  = [[UIPopoverController alloc] initWithContentViewController:profile];
    [profilePop setPopoverContentSize:CGSizeMake(350, 180)];
    [profilePop presentPopoverFromRect:CGRectMake(0,0, cell.avatar.frame.size.width, cell.avatar.frame.size.height) inView:cell permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

【问题讨论】:

    标签: iphone objective-c uipopovercontroller


    【解决方案1】:

    我会在您的个人资料类中保留对弹出框的引用。

    profile.popOver = profilePop;
    

    然后在你想解散的区域:

    [self.popover dismissPopoverAnimated:YES];
    

    【讨论】:

    • 这可能是要走的路。在许多其他情况下,您希望将其他消息从内容视图控制器发送到第一个视图控制器,因此这是一个很好的模式。
    【解决方案2】:

    我认为保留引用也是要走的路,但我不知道保留它是否是个好主意,因为当您需要释放弹出框控制器时,它不会释放,因为有一个额外的保留.

    【讨论】:

      猜你喜欢
      • 2012-04-10
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      相关资源
      最近更新 更多