Continue with the last helloworld program. Next we will add a button event for this application!
Start with me:
1. Continue the last tutorial. Because we have created the hellobailu label control last time, open the XIB file and we will create the uncreated button!
We create two button controls, one named showlabel and the other named return! They are used to display the label content and return (Change) the label content.
Drag the button control to any position on the Virtual Interface to add it.
2. After the button is successfully added, click on the simulation interface. The corresponding button attribute appears on the right side. Modify the corresponding attribute as needed. Then we only modify the title and change it to showlabel ..
The corresponding button content on the button will also change.
3. The following is the preparation for connecting label events we need. To enable viewcontroller. H, first create two labels: ilabel and rlabel. Simply put, the functions of these two labels are described, that is
The changed content is displayed on the displayed Hello Bailu Babel. When we click showlabel, the label displays "Bailu welcome". When we click return, the label displays other content.
4. after the creation, click the XIB file, right-click the file own file in the box, and the page appears. Then, associate the resume and associate all the labels of ilabel and rlabel with the label.
5. Implement the ilabel and rlabel methods. Here we should swap the location with Step 1. We should implement this method first.
6. Set events,
-(Ibaction) showlabel :( ID) sender {
Ilabel. Text = @ "Bailu welcome !!! ";
}
This means that when you click the showlabel button, the ilabel content will display Bailu welcome!
It's not hard to understand!
/*************************************** *************/
An error occurred while adding an event to the button;
-(Ibaction) return :( ID) sender {}
Here, the return in the. M file has nothing to do with the content displayed by the buttons in the XIB!
The event name does not need to be returned when an association is established and does not need to have the same content as the button in XIB.
/*************************************** ************/
The following is the same principle!
7. Switch to the XIB file and associate showlabel and return with the showlabel button and return button to complete the association! Here, the event is triggered by pressing the button.
The method for adding event listening to the control is now over!
If you have any questions, please join the group: Apple IOS software development alliance 57636364
My weibo http://weibo.com/cnbailu
Email: cnbailu@163.com
The code will be attached later!