提交时UIPopover崩溃

时间:2016-07-22 12:31:26

标签: ios uipopovercontroller presentviewcontroller

我有一个UILabel,我添加了一个UITapGestureRecognizer:

UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(nomLabelClicked)];
[nomLabel setUserInteractionEnabled:YES];
[nomLabel addGestureRecognizer:tap];
nomLabel.text = nom;
nomLabel.adjustsFontSizeToFitWidth = YES;
nomLabel.minimumScaleFactor = 0.6;

我调用的方法是这样的:

-(void)nomLabelClicked{
CGSize labelNomSize = [nomLabel.text sizeWithAttributes:@{NSFontAttributeName : nomLabel.font}];
if ((labelNomSize.width * 0.6) > nomLabelView.bounds.size.width) {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"AutoLayoutStoryboard" bundle:nil];
    ViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"ViewName"];
    UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:sfvc];
    sfvc.preferredContentSize = CGSizeMake(self.view.frame.size.width * 0.8, self.view.frame.size.height * 0.1);
    destNav.modalPresentationStyle = UIModalPresentationPopover;
    typePopover = destNav.popoverPresentationController;
    typePopover.delegate = self;
    typePopover.sourceView = self.view;
    typePopover.sourceRect = labelView.frame;
    destNav.navigationBarHidden = YES;
    dispatch_async(dispatch_get_main_queue(), ^(void){
        [self presentViewController:destNav animated:YES completion:nil];
    });
}

当我运行它并点击标签时,我首先得到这个:

*** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation_Sim/UIFoundation-432.1/UIFoundation/TextSystem/NSLayoutManager_Private.m:1551

然后我等了几秒钟,应用程序崩溃了,我明白了:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'

我已尝试添加dispatch_async(dispatch_get_main_queue(), ^(void){,但您没有改变任何内容。我理解错误:好像我在后台线程的某处更改了UI,但我似乎无法准确理解其中的位置并对其进行更改。奇怪的是,我似乎无法通过断点查明问题。所呈现的视图在所有断点处都是干净的,方法&#34; nomLabelClicked&#34;太。我有一个断点&#34;所有异常&#34;但它只是向我显示错误,它并没有在某个地方破坏。

0 个答案:

没有答案