Iphone 从UIViewController A转到B并获得反馈

Iphone 从UIViewController A转到B并获得反馈,iphone,ios,objective-c,Iphone,Ios,Objective C,我通过以下代码从视图控制器A转到B: [self presentViewController:B animated:YES completion:^{ }]; 视图B被取消时,如何通知我,以及此时如何将一些参数从B发回A?您应该使用@协议在两个控制器之间设置委托关系。如果您查看Apple以获得指导,您可以看到此模式在许多提供的视图控制器中重复出现,如UIImagePickerControllerwithUIImagePickerController,它告诉代理imagePickerCo

我通过以下代码从视图控制器A转到B:

[self presentViewController:B animated:YES completion:^{
    }];

视图B被取消时,如何通知我,以及此时如何将一些参数从B发回A?

您应该使用
@协议在两个控制器之间设置委托关系。如果您查看Apple以获得指导,您可以看到此模式在许多提供的视图控制器中重复出现,如
UIImagePickerController
with
UIImagePickerController
,它告诉代理
imagePickerController:didFinishPickingMediaWithInfo:

,您应该设置代理关系在使用
@协议的两个控制器之间
。如果您查看Apple以获得指导,您可以看到此模式在许多提供的视图控制器上重复出现,如
UIImagePickerController
with
UIImagePickerController
,它告诉代理
imagePickerController:didFinishPickingMediaWithInfo:
创建协议并让视图控制器实施它。现在,在视图控制器B中创建一个属性委托,并将其委托设置为a。然后,当您要解除委托时,调用委托(即a)上的相应协议方法,以便a知道B已准备好解除委托,因此a在解除委托B之前执行其任务,然后解除委托B

您还可以使用presentingViewController从B访问A,或使用UIViewController的presentedViewController属性从A访问B
.

创建一个协议,并让视图控制器a实现它。现在,在视图控制器B中创建一个属性委托,并将其委托设置为a。然后,当您要解除委托时,调用委托(即a)上的相应协议方法,以便a知道B已准备好解除委托,因此a在解除委托B之前执行其任务,然后解除委托B

您还可以使用presentingViewController从B访问A,或使用UIViewController的presentedViewController属性从A访问B
.

当关闭视图控制器B时,请使用以下方法:

// This code goes inside View Controller B. Here "self.presentingViewController"
// refers to View Controller A
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
    //completion code here
}];

// In your View Controller A implement dismissViewControllerAnimated:completion:
// and call super. This code goes in View Controller A
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
    // Here you can add your custom code. 
    [super dismissViewControllerAnimated:flag completion:completion];
}
这样,视图控制器A将知道视图控制器B何时被解除


希望这有帮助

关闭视图控制器B时,请使用以下方法:

// This code goes inside View Controller B. Here "self.presentingViewController"
// refers to View Controller A
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
    //completion code here
}];

// In your View Controller A implement dismissViewControllerAnimated:completion:
// and call super. This code goes in View Controller A
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
    // Here you can add your custom code. 
    [super dismissViewControllerAnimated:flag completion:completion];
}
这样,视图控制器A将知道视图控制器B何时被解除

希望这有帮助