Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your above code you are using custom delegates and also you have used it for sending message to onecontroller class to another controller class. So below is the same sample code of custom delegates, it is working fine in similar way you have to implement and also the problem in your code is you are not setting the delegate, so please follow below how to set the same and call the method. here i have used your same method only return type i have defined as <code>NSString</code> in-spite of <code>void</code> for explaining purpose, but you can use <code>void</code> according to your requirement hope it will be helpful to you:-</p> <p>First Controller Class <code>AWindowController.h</code></p> <pre><code> @interface AWindowController : NSWindowController&lt;sampleDelegate&gt; { NSString *textA; } @property(readwrite,retain)NSString *textA; -(IBAction)doSet:(id)sender; @end #import "AWindowController.h" #import "BWindowController.h" @interface AWindowController () @end @implementation AWindowController @synthesize textA; - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { // Initialization code here. } return self; } - (NSString *)setTotalViewController:(BWindowController*)controller didTotalChange:(NSString*)total { NSLog(@"recieved"); return @"recieved"; } - (void)windowDidLoad { [super windowDidLoad]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. } -(NSString*)windowNibName { return @"AWindowController"; } -(IBAction)doSet:(id)sender { [self setTextA:@"Awindow Button Pressed"]; BWindowController *b=[[BWindowController alloc]init]; b.delegate=self; [b showWindow:self]; } @end </code></pre> <p>Second Controller Class <code>BWindowController.h</code></p> <pre><code> #import &lt;Cocoa/Cocoa.h&gt; #import "sampleDelegate.h" @class BWindowController; @protocol sampleDelegate &lt;NSObject&gt; @required //-(NSString *)getDataValue; - (NSString *)setTotalViewController:(BWindowController*)controller didTotalChange:(NSString*)total; @end @interface BWindowController : NSWindowController&lt;sampleDelegate&gt; { NSString *bTextValue; id&lt;sampleDelegate&gt;delegate; } @property(readwrite,retain)NSString *bTextValue; @property(readwrite,assign)id&lt;sampleDelegate&gt;delegate; @end #import "BWindowController.h" @interface BWindowController () @end @implementation BWindowController @synthesize bTextValue,delegate; - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { // Initialization code here. } return self; } - (NSString *)setTotalViewController:(BWindowController*)controller didTotalChange:(NSString*)total; { return nil; } - (void)windowDidLoad { NSString *str= [[self delegate]setTotalViewController:self didTotalChange:@"recieved"]; self.bTextValue=str; [super windowDidLoad]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. } -(NSString*)windowNibName { return @"BWindowController"; } @end </code></pre> <p>Attached screen shot in Output:- Below is window is the <code>AwindowController.h</code> class <img src="https://i.stack.imgur.com/3bKo1.png" alt="enter image description here"></p> <p>Below in the same above window pressing the button and when Awindow button pressed data will send<br> and notification will be recieved in Bwindow using above define custom delegates as attached in the screen shot. <img src="https://i.stack.imgur.com/hqTOd.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload