Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:01:47+00:00 2026-06-08T03:01:47+00:00

I am looking for a class that has an event list similar to how

  • 0

I am looking for a class that has an “event list” similar to how UIButton works where you can add multiple targets and selectors.

It’s easy enough to write one, but if Apple has already provided a solution I would rather use this than have more code to maintain.

Note:

This is for a non-visual class, so I don’t really want to use any of the UI specific stuff.

Edit:

I ended up rolling my own rudimentary event dispatcher type class using stacked NSDictionary instances.

@implementation ControllerBase
@synthesize eventHandlers;


- (id) init
{
    self = [super init];

    if (self!=NULL)
    {
        NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
        [self setEventHandlers: dict];

        [dict release];
    }

    return self;
}


-(void) addTarget: (id) target  action:(SEL) selector  forEvent:(NSString*) eventName
{
    NSString* selectorString =  NSStringFromSelector(selector);   
    NSMutableDictionary* eventDictionary = [eventHandlers objectForKey:eventName];

    if (eventDictionary==NULL)
    {
        eventDictionary = [[NSMutableDictionary alloc] init];
        [eventHandlers setValue:eventDictionary forKey:eventName];
    }

    NSArray* array = [NSArray arrayWithObjects:selectorString,target, nil];
    [eventDictionary setValue:array forKey: [target description]];
}

-(void) removeTarget: (id) target  action:(SEL) selector  forEvent:(NSString*) eventName;
{
    NSMutableDictionary* eventDictionary = [eventHandlers objectForKey:eventName];

    //must have already been removed
    if (eventDictionary!=NULL)
    {
        //remove event
        [eventDictionary removeObjectForKey:target];

        //remove sub dictionary
        if ([eventDictionary count]==0)
        {
            [eventHandlers removeObjectForKey:eventName];
            [eventDictionary release];
        }
    }


}

-(void) fireEvent:(NSString *)eventName
{
     NSMutableDictionary* eventDictionary = (NSMutableDictionary*) [eventHandlers objectForKey:eventName];

    if (eventDictionary!=NULL)
    {
        for(id key in eventDictionary)
        {
            NSArray* eventPair= [eventDictionary valueForKey:key];

            if (eventPair!=NULL)
            {

                NSString* selectorString = (NSString*)[eventPair objectAtIndex:0];

                //remove colon at end
                SEL selector = NSSelectorFromString ( [selectorString substringWithRange: NSMakeRange(0, [selectorString length]-1)] ) ;
                id target = [eventPair objectAtIndex:1];

                [target performSelector:selector];
            }

        }
    }

}

-(void) dealloc
{
    for(id key in eventHandlers) 
    {
        NSMutableDictionary* eventDictionary = (NSMutableDictionary*) [eventHandlers objectForKey:key];

        for(id key in eventDictionary)
        {
            [eventDictionary removeObjectForKey:key];
        }

        [eventDictionary release];

    }

    [eventHandlers release];
    [super dealloc];
}



@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:01:48+00:00Added an answer on June 8, 2026 at 3:01 am

    UIButton is a subclass of UIControl. UIControl manages the target/action list for each control event. It has a predefined set of control events, like UIControlEventTouchUpInside and UIControlEventValueChanged. Each control event is represented by a bit in a mask. The bitmask has four bits reserved for app-defined events (UIControlEventApplicationReserved = 0x0F000000).

    If UIControl doesn’t do what you want, you’ll need to roll your own event management.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's what I am looking to accomplish, I have a class that has an
I am looking for a utility class that can generate random certificate strings for
I'm looking for a parser that can extract methods from a java class (static
I've been looking around for a php class that allows the decryption / encryption
I'm looking for suitable .NET class that allows me to store a large number
Is there such a class that provides a page break line? I've been looking
I am looking for a class or method that takes a long string of
I was looking for some utility class/code that would take a java bean and
I am looking for help in determining if the class model that I am
I've been looking for a way to call a class's constructor that is analogous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.