• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Using NSNotificationCenter passing an object or value?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Using NSNotificationCenter passing an object or value?
      • From: Graham Cox <email@hidden>
    • Re: Using NSNotificationCenter passing an object or value?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: GKPeerPickerController: can't connect from the simulator?
  • Next by Date: Re: Using NSNotificationCenter passing an object or value?
  • Previous by thread: Re: GKPeerPickerController: can't connect from the simulator?
  • Next by thread: Re: Using NSNotificationCenter passing an object or value?
  • Index(es):
    • Date
    • Thread