Passing back info between delegates on ObjectiveC

后端 未结 3 1589
执念已碎
执念已碎 2020-12-22 11:39

I need to pass back an NSMutableArray of photos between a CameraSessionView; how store the photos taken from camera on an NSMutableArray, and a TableViewController how uploa

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 12:22

    Your CameraSessionView instance will be released from memory as soon as viewDidLoad ends. You need to store it in a property in PhotosTableViewController so that it is retained.

    Your delegate should also be defined as weak, e.g.

    @property (nonatomic,weak) id< CameraSessionViewDelegate >delegado;
    

    Then in your implementation of PhotosTableViewController, you'll need to implement the -(void)uploadPhotosFromCamera:(NSMutableArray*)photos; method.

    Also as this method is defined as @optional, you should check if the delegate responds to it before calling it.

       if([self.delegado respondsToSelector:@selector(uploadPhotosFromCamera:]){
            [self.delegado uploadPhotosFromCamera:_images];
       }
    

    This will prevent the app from crashing if the delegate method isn't implemented.

提交回复
热议问题