Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios VC被解雇时如何调用委托人?_Ios_Objective C_Appdelegate - Fatal编程技术网

Ios VC被解雇时如何调用委托人?

Ios VC被解雇时如何调用委托人?,ios,objective-c,appdelegate,Ios,Objective C,Appdelegate,我有两个。当第二个VC被解除时,我需要调用委托函数 在我的第一个VC或主VC中,我在.h文件中给出了以下代码 @interface FirstVC : ....<SecondVCDelegate> -(void)didDismissViewController:(UIViewController*)vc; 在第二个VC.h文件中 @protocol SecondVCDelegate <NSObject> - (void)didDismissViewController

我有两个。当第二个VC被解除时,我需要调用委托函数

在我的第一个VC或主VC中,我在.h文件中给出了以下代码

@interface FirstVC : ....<SecondVCDelegate>
-(void)didDismissViewController:(UIViewController*)vc;
在第二个VC.h文件中

@protocol SecondVCDelegate <NSObject>
 - (void)didDismissViewController:(UIViewController*)vc;
@end

@interface SecondVC : ...
 @property (nonatomic) id<SecondVCDelegate> delegate;
@end

你能解释一下我做错了什么吗。提前感谢。

这是xcode 9上的工作代码:

ViewController.m:

#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController () <SecondVCDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)action:(id)sender {
    SecondViewController *optionsVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    optionsVC.delegate = self;
    optionsVC.view.backgroundColor = [UIColor blackColor];
    optionsVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    [self presentViewController:optionsVC animated:YES completion:nil];
}

-(void) didDismissViewController:(UIViewController *)vc{
    NSLog(@"working controller : %@", vc);
}
@end
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)didmissAction:(id)sender {
    [self dismissViewControllerAnimated:true completion:^{
        [_delegate didDismissViewController:self];
    }];
}

@end

在你的第二次风险投资中,我喜欢这样做

首先在实现下面合成委托

@synthesize delegate;
之后,在viewController上使用它:

[self dismissViewControllerAnimated:YES completion:^{

    [self.delegate didDismissViewController: self];
}];

您可以在第二个VC的完成块中调用它,当您解除view@RahulGUsai如何??在第二个VC中调用委托方法的位置?例如[self-dismissViewControllerAnimated:YES completion:^{call delegate here}]@拉胡古赛:我已经试过了,但我需要解雇这第二位VC,转而成为新的VC。但由于某些原因,它不起作用。@syntesize做什么?试图使委托属性变弱<代码>@property(弱,非原子)id委托可以避免保留循环。
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)didmissAction:(id)sender {
    [self dismissViewControllerAnimated:true completion:^{
        [_delegate didDismissViewController:self];
    }];
}

@end
@synthesize delegate;
[self dismissViewControllerAnimated:YES completion:^{

    [self.delegate didDismissViewController: self];
}];