Using NSNotificationCenter passing an object or value?
Using NSNotificationCenter passing an object or value?
- Subject: Using NSNotificationCenter passing an object or value?
- From: "Eric E. Dolecki" <email@hidden>
- Date: Tue, 3 Aug 2010 15:34:09 -0400
I am trying to pass along a custom UIButton's tag down to another class I am
writing.
In my custom view which contains the custom UIButton, I have this code *(A):
*
-(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.
Sorry for the noob question.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden