2017-03-01 72 views

回答

1

使用滿足您需求的方法添加。讓掌握字典的班級符合。實施有問題的方法並在其中編輯您的字典。在其他課程中,添加一個@property (weak, nonatomic) id <MyProtocol> delegate或其他適當的名稱。需要時通過存儲的delegate調用協議。

@protocol MyProtocol <NSObject> 
    - (void)callback; 
@end 

@interface MyClass : NSObject <MyProtocol> 
@property (nonatomic, copy) NSMutableDictionary *myDictionary; 
@end 

@implementation MyClass 
// class methods 

    -(void)callback { 
    // edit dict here 
    } 

@end 

@interface MySecondClass : NSObject 
@property (weak, nonatomic) id<MyProtocol> delegate; 
@end 

@implementation MySecondClass 
// class methods 

- (void)someMethod { 
    // some logic 
    if ([self.delegate respondsToSelector:@selector(callback)]) { 
    [self.delegate callback]; 
    } 
} 
@end 
相關問題