Error when dismissing view controller

前端 未结 6 1701
时光取名叫无心
时光取名叫无心 2021-02-07 07:52

Getting an error when dismissing a view controller, not seen anything like it before, and not much about it on the internet.

heres the error: * Assertion failur

6条回答
  •  终归单人心
    2021-02-07 08:11

    In the target view controller define delegate and protocol:
    
    @class TargetVC;
    @protocol TargetVCDelegate 
    -(void)dismissTargetVC:(TargetVC*)vc;
    @end
    
    @interface TargetVC : UIViewController
    @property (nonatomic, weak) id delegate;
    @end
    
    when you done the job at the target view controller call the delegate:
    if( [self.delegate respondsToSelector:@selector(dismissTargetVC:)])
    {
       [self.delegate dismissTargetVC:self];
    }
    
    The implementation of the delegate protocol should be:
    -(void)dismissTargetVC:(TargetVC*)vc
    {
        [vc dismissViewControllerAnimated:YES completion:nil];
    
        // you can get relevant data from vc as you still hold reference to it in this block
    
        // your code ...
    }
    

提交回复
热议问题