0

在我的应用程序中,我试图将数据从父视图传递到子视图。但是,当我运行应用程序时,不会调用委托方法。这是我如何实现自定义委托的代码:parent.h

    @protocol SLBWallViewControllerDelegate <NSObject>

- (void) pictureToBeUploaded:(id)picture;

@end

@interface SLBWallViewController : UIViewController <UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
- (IBAction)createPotButtonPressed:(id)sender;

@property (weak, nonatomic) id <SLBWallViewControllerDelegate> delegate;
@end

父母.m

[self.delegate pictureToBeUploaded:info[UIImagePickerControllerEditedImage]];//i'm taking the pic from a uiimagepicker

孩子.h

@interface SLBPostViewController : UIViewController <SLBWallViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *picture;
@end

孩子.m

#pragma mark - Wall View Controller Delegate
- (void)pictureToBeUploaded:(id)picture{
    self.picture.image = picture;
}

有什么错误或遗漏吗?

4

2 回答 2

1

好吧,问题可能(编辑:在评论中确认)就是self.delegate那个nil时候。因此,您发送消息到nil,当然没有任何反应。您需要做的是确保在尝试发送消息之前将Child实例分配给属性。delegate例如这样的事情:

//...
self.delegate = //.. a 'Child' instance

//...
[self.delegate pictureToBeUploaded:info[UIImagePickerControllerEditedImage]];
于 2013-07-11T11:03:06.390 回答
0

//(1) 在.h文件的Child中创建一个属性

@property (nonatomic,strong) UIImage * someImage;

//(2) 在.m文件中的Child覆盖属性

-(void)setSomeImage:(UIImage *)someImage{

_someImage=someImage;
self.picture.image = self.someImage;

}

//(3) 在 .m 文件的 Parent 中,将图像设置为孩子的 'someImage' 属性

childsObject.someImage= UIImagePickerControllerEditedImage;

于 2013-07-11T10:28:12.893 回答