How to call a method from a different class?
<p>So, I am trying to make a shared method in my Brain class which will check the label on a pressed button (buttons of items are in different classes) and then accordingly add a image to a ShoppingList view minding the order of adding (first image added goes to position 0,0, second to position 80,0 etc.).</p>

<p>I have Breakfast class which represents breakfast ingredients and I wanna add a photo of a Tea to another view called ShoppingList.</p>

<p>I wrote a method in Brain that adds an image to a imageView and returns an imageView which is then locally passed to the button pressed.</p>

<p>It builds but when I press the button Tea, application crashes.</p>

<p>Here is my code:</p>

<p><strong>Brain.h</strong></p>

<pre><code>@interface Brain : NSObject {
@private
    UIImage *image;
    UIImageView *imageView;

}

@property (retain) UIImageView *imageView;
@property (retain)  UIImage *image;

- (id)performOperation:(NSString *)operation;
@end
</code></pre>

<p><strong>Brain.m</strong></p>

<pre><code>@implementation Brain

@synthesize imageView;
@synthesize image;

- (UIImageView *)performOperation:(NSString *)operation
{
    if ([operation isEqual:@"Tea"]) {
        image = [UIImage imageNamed:@"Tea_photo.jpg"];
        imageView = [[UIImageView alloc]initWithImage:image];

        imageView.frame = CGRectMake(0, 0, 80, 80);

        return imageView;


        //[shoppingList.view addSubview:imageView];
        //[imageView release];

    }

    else return 0;
}

@end
</code></pre>

<p><strong>Breakfast.h</strong></p>

<pre><code>@interface Breakfast : UIViewController {

    IBOutlet ShoppingList *shoppingList;
    Brain *brain;

}
- (IBAction)addItemToShoppingList:(UIButton *)sender;

- (IBAction)goToShoppingList;

- (IBAction)goBack;


@end
</code></pre>

<p><strong>Breakfast.m</strong></p>

<pre><code>@implementation Breakfast

- (Brain *)brain
{
    if (!brain) brain = [[Brain alloc] init]; 
    return brain;

}



- (IBAction)addItemToShoppingList:(UIButton *)sender
{
    NSString *operation = [[sender titleLabel] text];
    UIImageView *imageView = [[self brain] performOperation:operation];
    [shoppingList.view addSubview:self.brain.imageView];

    //UIImageView *imageView = [[UIImageView alloc]initWithImage:image];

    //imageView.frame = CGRectMake(0, 0, 80, 80);


    //[shoppingList.view addSubview:imageView];
    //[imageView release];

}
- (IBAction)goToShoppingList
{
    [self presentModalViewController:shoppingList animated:NO];
}

- (IBAction)goBack
{
    [self dismissModalViewControllerAnimated:NO];
}

@end
</code></pre>

<p><strong>PLEASE HELP</strong>, its for my thesis.</p>
