开发者

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 successfull开发者_如何学编程y 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜