iOS action (action) and output port (Outlet)


Introduction

In iOS, actions and outputs refer to ibActions and ibOutlets, which is where the ib interface generator is located. These are all related to UI elements. We will understand them intuitively and then discuss how to implement them.

Steps

1. Let’s use the first iPhone application.

2. Select the ViewController.xib file from the files in the navigation section

3. Select the UI element from the window grid displayed below the window on the right

objectLibrary

4. Drag UI elements into the visual frame of the interface builder

5. Add labels and red round buttons to the visual frame

interfaceAction

6. Find the editor selection button in the upper right corner of the workspace toolbar, as shown below

StandardEditor

Select the editor button

AssistantEditor

7. There are two windows in the center of the editor area, ViewController.xib file and ViewController.h

8. Right-click the selection button on the label, press and drag Move the new reference, as shown below

ibOutletDrag

#9. Now place it in the curly brackets between ViewController.h. It can also be placed in a file, if so it must have been added before doing this. As shown below

ibOutletDrop

#10. The label name of the input and output port (Outlet), here is myTitleLable. Click the link to complete ibOutlet

11. Similarly, to add operations, just right-click the rounded rectangle, select Touch the Heart and drag the braces below it

ActionDrag

12. Rename it to setTitleLable

ActionDrop

13. Select the ViewController.m file, there is a method as shown below

-(IBAction) setTitleLabel:(id)sender{}

14. In the above method, add a statement as shown below

[myTitleLabel setTitleText:@"Hello"];

15. Select the run button to run the program and get the following output

IBActionTutorial.Simulator_Start

16. Click the button

IBActionTutorial.Simulator_end

17. The created reference (outlets) button label has been changed to the button execution Operations

18. As can be seen from the above, IBOutlet will create a reference to UIElement (here UILable), and the same IBAction and UIButton are linked to UIButton by performing operations.

19. You can perform different operations by selecting different events when creating an action.