Good morning,
I would like to ask for clarification re. a specific instance of the error message noted in the title. I recognize that this error has been discussed numerous times before & I have looked thru' about 10 of those threads to see if I can find an answer to my problem but I cannot so pls. bear with me.
My App uses the iPhone to control the actions of a program running on a PC. It is customized to that program rather than using a generalized VNC. It uses a tabBarController with 4 screens. The viewController associated with the first tab initiates the "model" which is the client that communicates with the server on the PC. The second and third VCs have buttons which send commands to the server via the client. All works fine with those.
My problem is with the fourth VC which is intended to display data received from the server via the client. When the client (i.e. model) receives data for display, I am trying to use NSNotification (with an attached array of data in userinfo) to send a message to the fourth VC to tell it to update its labels' text properties. My first attempt resulted in an error message similar to the one in the question title. I hypothesized that this was because the 4th VC had not been created at the time the first data was sent to it. To avoid this, I added a condition in the model so it will not send data until it receives a message from the 4th VC once it is loaded. However, when the execution reaches the line in the 4th VC's ViewDidAppear where the notification is sent, I get the error message in the title.
Again, reading other threads, I concluded that it cannot find the selector in the model class because the model has gone out of memory and been replaced by the 4th VC. Hence it looks for the selector in the 4th VC and cannot find it. So, with apologies for that long pre-amble, my question is how do I keep my "model" in memory so that the notification has an appropriate destination.
Here is some code from the 4th VC showing the notification set up, etc.
// DataDisplayViewController.m
#import "DataDisplayViewController.h"
#import "VVViewController.h"
#import "VVC_Communication_Module.h"
@interface DataDisplayViewController ()
@property (nonatomic, strong) NSMutableArray *rideData;
@end
@implementation DataDisplayViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ddvcLoadedRcv) name:@"ddvcLoadedEvent" object:nil];
}
- (void) viewDidAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ddvcLoadedEvent" object:nil];
}
@end
Here is some code from the model showing the selector that is supposed to get the notification.
// VVC_Communication_Module.m
#import "VVC_Communication_Module.h"
#import "VVViewController.h"
#import "DataDisplayViewController.h"
@interface VVC_Communication_Module()
@property (nonatomic, strong) NSArray *itemArray;
@property (nonatomic) BOOL ddvcLoaded;
@end
@implementation VVC_Communication_Module
@synthesize itemArray;
@synthesize ddvcLoaded = _ddvcLoaded;
- (BOOL) ddvcLoaded
{
_ddvcLoaded = NO;
return _ddvcLoaded;
}
- (void) ddvcLoadedRcv:(NSNotification *) notification
{
_ddvcLoaded = YES;
}
@end
Finally, some code from the 1st VC that instantiates the model:
// VVViewController.m
#import "VVViewController.h"
#import "DataDisplayViewController.h"
#import "VVC_Communication_Module.h"
@interface VVViewController ()
@property (nonatomic, strong) VVC_Communication_Module *moduleRxTx;
@end
@implementation VVViewController
@synthesize moduleRxTx = _moduleRxTx;
- (VVC_Communication_Module *)moduleRxTx
{
if (!_moduleRxTx) _moduleRxTx = [[VVC_Communication_Module alloc] init];
return _moduleRxTx;
}
@end
Thank you for all and any help you can offer. RB
you enter
@selector(ddvcLoadedRcv)
but it should be@selector(ddvcLoadedRcv:)
because your method takes an argument. furhermore you tell your notification that the methodddvcLoadedRcv:
is found in "self" but you must point to an object of typeVVC_Communication_Module
where the method is defined