On Aug 3, 2010, at 12:34, Eric E. Dolecki wrote:

> -(void) buttonClicked:(id)sender
> {
>     [[NSNotificationCenter defaultCenter]
> postNotificationName:@"ButtonClicked"
> object:sender];
> 
> 
> In a class which manages these custom views, I have this code *(B):*
> 
> 
> - (id)initWithFrame:(CGRect)frame {
>    if ((self = [super initWithFrame:frame])) {
>        mydata = [[NSArray alloc] init];
>        menuItems = [[NSMutableArray alloc] initWithCapacity:40];
>        [[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(buttonClicked)  name:@"ButtonClicked" object:nil];
>    }
>    return self;
> }
> 
> -(void) buttonClicked {
>    //This works, but I need to know the tag
>    NSLog(@"clicked");
> }
> 
> Now, obviously in that I have object set to nil. How can I set this up? I
> could change object to nil and use userInfo:someNSDictionary in the
> customview which contains the UIButton... but I run into the same problem
> in *(B). * I really haven't seen much in Google in regards to userInfo and
> looking for some help on it. I understand some of how it works, not sure how
> to set that *addObserver* part up properly.

You *really* need to read the documentation. Your second "buttonClicked"  
method prototype is wrong -- it takes a NSNotification object as a parameter. 
If you had coded that properly, you would have a way of getting the 
notification's userInfo. (Or, to get the object and ask it for its tag. Or 
whatever.)

Your first "buttonClicked" method (why give them the same name?) can use 
'postNotificationName:object:userInfo:' if you really need to pass userInfo. 
(Again, you don't need to use userInfo if you just want the button's tag.)


_______________________________________________

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