CallMeRex
CallMeRex

Reputation: 125

Messaging the Model in my MVC

To preface, I'm very new to Obj-C but I do have some OOP experience in C++ and Java.

So I've started reading and learning Obj-C for iphone dev, and now I'm attempting to make my very first MVC program.

Basically what I've done is create a button, and now I want my controller to message my model upon pressing the button. I've verified the controller method is successfully being called but im unable to successfully message my model from the controller. I don't know why but the function (void)myfunction isn't executing.

My controller is called TestViewController, and my model is called Brain.

//TestViewController.m
#import "TestViewController.h"

@implementation TestViewController

- (Brain *)mybrain
{
    if (!mybrain)mybrain = [[Brain alloc] init];
    NSLog(@"mybrain is initialized..");
    return mybrain;
}


- (IBAction)buttonPressed:(UIButton *)sender 
{
    NSLog(@"Controller has been messaged!");
    [mybrain myfunction];
}


//Brain.m
#import "Brain.h"
@implementation Brain

-(void)myfunction
{
    NSLog(@"Model has been messaged!");
    return;
}

@end

Upvotes: 0

Views: 88

Answers (1)

Colin Wheeler
Colin Wheeler

Reputation: 3343

are you retaining the myBrain object? it looks like this code is incomplete. the first thing I see in the code sample as it is at the moment is that there is no retaining of the myBrain object anywhere. So its very possible its leaking and you are messaging nil and thus nothing happens.

Upvotes: 1

Related Questions