Ios 为什么代理不工作?

Ios 为什么代理不工作?,ios,objective-c,delegates,delegation,Ios,Objective C,Delegates,Delegation,我的代表: @class UpdateUserSummary; @protocol UpdateSummaryDelegate <NSObject> - (void)updateSummaryDidCancel:(UpdateUserSummary*)controller; - (void)updateSummaryDone:(UpdateUserSummary*)controller; @end -(void)updateSummaryDidCancel:(UpdateUse

我的代表:

@class UpdateUserSummary;
@protocol UpdateSummaryDelegate <NSObject>

- (void)updateSummaryDidCancel:(UpdateUserSummary*)controller;
- (void)updateSummaryDone:(UpdateUserSummary*)controller;

@end
-(void)updateSummaryDidCancel:(UpdateUserSummary *)controller
{
    // just close modal vc
    [self dismissViewControllerAnimated:YES completion:nil];
 }
用这个,, UpdateUserSummary.delegate=self;
您在实现类中调用委托的位置。

您需要澄清您的问题到底是什么,您发布的代码没有解释它。您是否设置了UpdateUserSummary.delegate=self@your实现UpdateSummaryDelegate协议的类?是的,在上一个版本中,它工作正常,当我添加新的视图控制器时,我遇到了这个问题,但我撤消了我所做的所有操作,但什么都不做。一个UpdateUserSummary对象一次只能为一个实现者设置它的委托,解决方法是声明delegate1、delegate2等,因为多个视图控制器正在共享it@CalinChitu,你说得对,,我能做些什么来避免这个?这就是你的意思吗(iAction)done:(id)发送方{[self.delegate updatesummarydidconcel:self];}我想你找到了解决方案。请参考正式协议。这是你的意思吗?接口UpdateUserSummary:UIViewController@property(非原子,弱)id委托;end-(iAction)done:(id)发送方{[self.delegate updateSummaryDidCancel:self];}确保在调用委托方法的类中设置委托属性。“mUpdateSummary.delegate=self;”@interface DEMOSecondViewController()“”-(void)updateSummaryDidCancel:(UpdateUserSummary*)控制器“”{“”//只需关闭模式vc“”[self dismissViewControllerAnimated:是完成:无];”}”
-(void)updateSummaryDidCancel:(UpdateUserSummary *)controller
{
    // just close modal vc
    [self dismissViewControllerAnimated:YES completion:nil];
 }
@protocol MUpdateSummaryDelegate;

@interface MUpdateSummary : NSObject

@property (assign) id<UpdateSummaryDelegate> delegate; //You need this

@end


@protocol UpdateSummaryDelegate <NSObject>

-(void)updateSummaryDidCancel:(UpdateUserSummary *)controller;

@end
MUpdateSummary *mUpdateSummary = [[MUpdateSummary alloc] init];
mUpdateSummary.delegate = self;