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.
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.
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.
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.
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};
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With