0

I have two view controllers VC1 and VC2. I pass a value from VC1 to VC2 through prepareForSegue method. and when I receive that value in VC2 I multiply it by 10. Then after multiplying that value by 10 in VC2 I want to return it back to VC1.

to solve this issue, I would use Delegate. so, I created DelegateDataProcessor class

but I do not know how to call the required method processingDone in the method startProcessingValue

please have a look at the code below

** DelegateDataProcessor.h**:

 #import <Foundation/Foundation.h>

 @protocol ProtocolDataProcessor <NSObject>

 @required
 - (void) processingDone;
 @end


 @interface DelegateDataProcessor : NSObject{

 id <ProtocolDataProcessor> _delegate;
 }

 @property (nonatomic, strong) id delegate;

-(void) startProcessingValue: (NSInteger) valueToBeProcessed;

@end

** DelegateDataProcessor.m**:

#import "DelegateDataProcessor.h"

@implementation DelegateDataProcessor

-(void) startProcessing:(NSInteger) value {

 value = value * 10;

//How to call the method `processingDone` here

}
@end
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    Possible duplicate of [How do I create delegates in Objective-C?](https://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c) – luk2302 Aug 04 '17 at 18:08
  • @user2121 - you would benefit greatly by reading through that linked post, as well as a few other articles / tutorials / documentation pages so that you **understand** how Delegate Protocols work... however, if you just want a quick answer without any context: `[_delegate processingDone];` – DonMag Aug 04 '17 at 18:41
  • I think you are a bit confused on how to achieve delegation.. I came here from your prev question.. feel free to pm me fb.com/mrpatrnogic i can explain you how to properly implement this later if you want – Marcio Romero Patrnogic Aug 04 '17 at 22:49

1 Answers1

0

You can pass your data from VC2 to VC1 via a protocol:

  • Add a method to protocol:

    -(void)getValue:(NSInteger)myInteger;
    
  • On method prepare for segue, define VC1 as VC2's delegate

  • When you want come back from VC2 to VC1 call method getValue by passing your value.

I wish that I explained clearly.

Pang
  • 9,564
  • 146
  • 81
  • 122
Imed Ben Aoun
  • 97
  • 1
  • 3