【问题标题】:Weird delay in UIPopoverController dismissalUIPopoverController 解雇的奇怪延迟
【发布时间】:2015-07-15 06:28:57
【问题描述】:

也许这纯粹是模拟器相关的。我还没有在实际设备上尝试过。

我使用的是最新款最棒的 MacBook,它配备 1TB 闪存驱动器、95% 的可用处理器,并且内存消耗低于全部内存消耗。

我有一个 UIPopoverController,里面有 4 个项目,大小与这些项目相符。 所讨论的 UIPopoverController 中没有任何复杂的、多线程的或长时间运行的东西。

我已将出现和关闭动画设置为 0,但是当我点击列表中的某个项目时,弹出框消失时似乎存在 0 到 0.4 秒之间的随机不确定延迟。当然 0 是意料之中的,但接近半秒的时间明显更长且令人不安。

知道是什么原因造成的吗?

显示弹出框的代码...

-(IBAction)theLandImpsButtonPressed:(UIButton *)sender
{
    iRpNameValuePopover *thePopoverContent = [[iRpNameValuePopover alloc] init];
    thePopoverContent.theTableValues = [self getLandImpsChoicesList];
    impsLandPopover = [[UIPopoverController alloc] initWithContentViewController:thePopoverContent];
    thePopoverContent.thePopoverController = impsLandPopover;
    impsLandPopover.popoverContentSize = [iRpUIHelper sizeForPopoverThatHasTitle:NO andListContent:thePopoverContent.theTableValues];
    impsLandPopover.delegate = self;

    [impsLandPopover presentPopoverFromRect:self.theLandImpsButton.bounds inView:self.theLandImpsButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}

关闭弹出框的代码... 顺便说一句,[self userChoiceIsValid] 这里没有评估时间,因为它现在只是返回 YES。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _theChosenNameValueItem = [self.theTableValues objectAtIndex:indexPath.row];
    [self acceptUserChoiceAndClose];
}


// This contentViewController is encapsulated INSIDE a UIPopoverViewController, and this class cannot itself
// close the popover which contains it, hence the need for the reference to the popover controller
// It is the popover's delegate... the one that created the popover, that is able to close it.
-(void)acceptUserChoiceAndClose
{
    _theUserChoseAValue = NO; // Start by assuming they didn't chose a valid value.

    if ([self userChoiceIsValid])
    {
        // Set variable that indicates the user chose a value which can be saved to core data, and/or presented on screen.
        _theUserChoseAValue = YES;

        // Close the popover.
        [_thePopoverController dismissPopoverAnimated:NO];

        // Notify the class that presented the popover that the popover has been dismissed.
        // It will still be available to the dismissal method where code can retrieve the user's choice, and set the popover to nil.
        if (_thePopoverController.delegate && [_thePopoverController.delegate respondsToSelector:@selector(popoverControllerDidDismissPopover:)])
        {
            [_thePopoverController.delegate popoverControllerDidDismissPopover:_thePopoverController];
        }
    }
    else
    {
        [self showValidationFailureMessageToUser];
    }

}

【问题讨论】:

  • 能否请您发布您的代码,以便我们了解问题所在。
  • 你有没有想过这个问题?
  • @Pavan Hah...好吧,过去 18 个月里代码变化太大了,我什至找不到这个代码了。
  • @LogicsaurusRex 你是在告诉我你不再在任何地方显示弹出框了吗? ;) 也许你现在是怎么做的,等等。哈哈

标签: ios objective-c uipopovercontroller


【解决方案1】:

关闭主线程中的viewController 将解决问题。

dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:YES completion:nil];
});

【讨论】:

    【解决方案2】:

    我会在分析器中检查它,看看花费的时间。

    有一个很好的教程here

    【讨论】:

      【解决方案3】:
      UIPopoverPresentationController *popOverView;
      //////
      

      忽略它...

      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
              dispatch_async(dispatch_get_main_queue(), ^{
                  [popOverView.presentedViewController dismissViewControllerAnimated:NO completion:nil];
                  popOverView = nil;
              });
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-02
        • 2014-07-31
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多