Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom events?

Tags:

iphone

I have a view1 with a subview view2, where i have a UIButton button that has fires an action soSomething:

view1
--view2
----IBOutlet UIButton *button
-----(IBAction) doSomethingid)sender

clicking the button calls doSomething. now how can i dispatch a custom event in doSomething and catch it at the view1?

eg in view2:

Code:

-(IBAction)doSomething:(id)sender{
  // Disptach the event for the parent "superView" to receive

}

then in view1 have something that handles that event.

like image 202
Sweety Avatar asked Apr 22 '11 06:04

Sweety


People also ask

How do you create a custom event on Facebook?

To do this, navigate to your Facebook pixel page in Events Manager and click the Custom Conversions tab on the left. In the upper-right corner of the page, click Create Custom Conversion. Next, enter the URL of the page on which you want the custom conversion to fire and type in a name for the event.

How do you define a custom event?

Custom event definitions are event definitions that have been created from scratch in the event definition editor rather than having been generated from existing events by the event definition generator.

What are the two types of custom events?

Application Event: Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified. Component Event: A component event is fired from an instance of a component.

How do I create a custom event in react?

addEventListener(eventName, listener); } function unsubscribe(eventName, listener) { document. removeEventListener(eventName, listener); } function publish(eventName, data) { const event = new CustomEvent(eventName, { detail: data }); document. dispatchEvent(event); } export { publish, subscribe, unsubscribe};


1 Answers

In your action event

// Dispatch the event for the parent "superView" to receive
-(IBAction) doSomething:(id)sender{
    [[NSNotificationCenter defaultCenter] postNotification:@"SomeEventName"];
}

in your view1 viewdDidLoad method write this code

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(methodToHandel) name:@"SomeEventName" object:nil];

and add this method to handle that event

-(void) methodToHandel{
    // this method get call 
}
like image 62
Crazy Developer Avatar answered Sep 28 '22 19:09

Crazy Developer