On May 30, 2009, at 5:43 PM, Pierre Berloquin wrote:

Declaring in .h

-(void)vagTouchesBegan:(id)sender;
was my first impulse. But that's not enough.

It's not clear from your two posts which method you're getting a warning for. I thought it was for the -vagTouchesBegan method, but you claim it's not. Please post the actual warning that you get from XCode.

About the memory problem, I suppose I should receive touchesBegan in the
controller and sort out what I get ?

No, that's not what I was referring to. I was referring to the fact that if an object of class A retains an object of class B and that same object of class B also retains the object of class A which retains it, then you have what's called a retain cycle. That may cause you trouble if you're not careful.

The view controller already retains its view, so if you're passing the view controller object to the view object for it to keep, then the view object should NOT retain that view controller object. If what I just said isn't completely clear to you, you should read

http://devworld.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

If that document is still a bit obscure, then you should search the web for more accessible explanations. For instance,

http://stackoverflow.com/questions/791322/retain-cycles-why-is-that-such-a-bad-thing

Note that it *is* ok for the view object to have a pointer to its view controller. All I'm saying is that you should avoid retaining the view controller in its view. Thus, instead of

- (void) setViewController: (UIViewController*) vcontroller
{
    [viewController release];
    viewController = [vcontroller retain];
}

(which is the typical setter for objects) you should have

- (void) setViewController: (UIViewController*) vcontroller
{
    viewController = vcontroller; // Note: no release and no retain
}

(atypical for objects, but necessary in this case to avoid a retain cycle).

Or, if you prefer to use properties, instead of

@property (readwrite, nonatomic, retain) UIViewController* viewController;

you should use

@property (readwrite, nonatomic, assign) UIViewController* viewController;

Wagner

2009/5/30 WT <jrca...@gmail.com>

On May 30, 2009, at 4:40 PM, Pierre Berloquin wrote:

[theViewController vagTouchesBegan:self];
QED
There's still a warning that the view controller may not respond. But it
works seamlessly.
Can I get rid of the warning?


Yes, by declaring the method -vagTouchesBegan: in the header file of your
view controller class.

Something to be cautious about when storing in the view a pointer to its view controller is that you may end up creating a retain cycle, since the view controller already retains its view. I would recommend that you read
the documentation on memory management to make sure you don't create
unnecessary problems for yourself.

Wagner
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to