ios - UIPopoverController 解雇出现奇怪的延迟

标签 ios objective-c uipopovercontroller

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

我使用的是最新款最出色的 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];
    }

}

最佳答案

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

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

关于ios - UIPopoverController 解雇出现奇怪的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31422980/

相关文章:

objective-c - 如何在具有相同键的其他值之间获取特定值

objective-c - 我可以集成 Jenkins 和 XCTest 吗

iOS 从条形按钮项目底部呈现 Popover

ios - 如何在 iOS 8 中正确显示弹出窗口

iphone - 模态视图显示不正确

ios - AudioConverterRef 采样率转换 (iOS)

ios - iphone 5c还够发布ios应用吗?

iphone - 以编程方式访问 iOS 中的地址簿?

objective-c - 多个 View Controller 中的 CLLocation

ios - 关闭 UIPopoverController 不会卸载 contentController