UIPopoverController被解雇的奇怪延迟

时间:2015-07-15 06:28:58

标签: ios objective-c uipopovercontroller

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

我使用1TB闪存驱动器,95%免费处理器,以及低于完全内存消耗的最新MacBook。

我有一个UIPopoverController,里面有4个项目,大小适合这些项目。 在UIPopoverController中没有任何复杂或多线程或长时间运行的关联。

我已将出现和解除动画设置为0,但是当我点击列表中的某个项目时,在弹出消息中0到0.4秒之间似乎存在随机的不确定延迟。当然0是预期的,但是它接近半秒的时间非常明显更长并且令人不安。

知道可能导致这种情况的原因吗?

显示popover的代码......

-(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];
}

解雇popover的代码...... 顺便说一句,[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];
    }

}

3 个答案:

答案 0 :(得分:1)

我会在探查器中查看它,看看花了多少时间。

有一个很好的教程here

答案 1 :(得分:1)

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

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

答案 2 :(得分:-1)

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;
        });
    });