Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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 使用不起作用的委派解除ViewController_Ios_Iphone_Objective C_Delegates - Fatal编程技术网

Ios 使用不起作用的委派解除ViewController

Ios 使用不起作用的委派解除ViewController,ios,iphone,objective-c,delegates,Ios,Iphone,Objective C,Delegates,我有两个via控制器,一个主VC,然后是一个分段VC。在我继续之前,我要确保让master成为继续VC的代理。连接已建立 在segued VC中,有一个按钮(有点像取消按钮)可以触发解雇。在segued VC中,我有以下代码: -(IBAction)deletePill:(id)sender { [delegate pillInfoViewControllerDidDeletePill:pill]; } 在master VC中,我所拥有的是: -(void) pillInfoVi

我有两个via控制器,一个主VC,然后是一个分段VC。在我继续之前,我要确保让master成为继续VC的代理。连接已建立

在segued VC中,有一个按钮(有点像取消按钮)可以触发解雇。在segued VC中,我有以下代码:

-(IBAction)deletePill:(id)sender    {
[delegate pillInfoViewControllerDidDeletePill:pill];
}

在master VC中,我所拥有的是:

    -(void) pillInfoViewControllerDidDeletePill: (Pill*) pill{
[self dismissViewControllerAnimated:TRUE completion:nil];
}

我在这里错过了什么

更新以回答评论并添加更多代码

回答问题并提供更多代码(我不想做代码转储)。我并不是以模型视图的形式来展示这一点。用户按下主VC中的按钮,启动推送序列。以下是推送序列的代码:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(UICollectionViewCell *)sender{
if([segue.identifier isEqualToString:@"pillInfo"]){
    pills=[[NSMutableArray alloc]initWithArray:[[self fetchedResultsController]fetchedObjects]];
    Pill* pillSelected =pills[sender.tag];
    PillInfoViewController *dest= [segue destinationViewController];
    [dest setPill:pillSelected];
    [dest setDelegate:self];
}

在解除呈现视图控制器时,不能调用呈现视图控制器的操作。为此,您可以按如下方式使用NSNotificationCenter:

-(IBAction)deletePill:(id)sender    {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationName" object:nil];
}
现在在主视图控制器中,在ViewDidLoad中添加以下代码:

[[NSNotificationCenter defaultCenter] addObserver:self
 selector:@selector(pillInfoViewControllerDidDeletePill)
 name:@"NotificationName" object:nil];
方法

-(void) pillInfoViewControllerDidDeletePill: (Pill*) pill
应该是协议的一部分,例如:

@protocol VCDismissingProtocol
@optional
-(void) pillInfoViewControllerDidDeletePill: (Pill*) pill;
@end
确保已声明主视图控制器实现该协议:

@interface MasterViewController : UIViewController<VCDismissingProtocol>{
...
}
@end
@interface MasterViewController:UIViewController{
...
}
@结束
segued view控制器声明一个委托属性,如下所示:

@property (weak,nonatomic) id <VCDismissingProtocol> delegate;
@属性(弱、非原子)id委托;

您解雇控制器是什么意思?您是否像modelView一样演示此内容?您将您的代表分配到了哪里?我已更新了问题以回答更多注释并添加更多代码:)一切都在那里。在
[delegate pillInfoViewControllerDidDeletePill:pill]上设置断点调用,并在该方法的实现中查看委托对象和调试-它设置正确吗?您还可以尝试使用
[self dismissViewControllerAnimated:YES completion:nil]
而不是
[self dismissViewControllerAnimated:TRUE completion:nil]