简体   繁体   中英

XCode 4 Interface Builder: How to access a drawn object

I'm very new to iPhone development.

I drew a View using the Interface Builder in XCode 4. Currently the only thing inside is a Label (taken from the Object Library in the Interface Builder (So this is a UILabel, right?) ). I've set the tag of it to 6543 as recognizable test-value.

Now, I'm trying to write a method which prints out the tag. My problem is that I can't access the Label that I drew in the Interface Builder.

I know I can get the tag from an id , doing this:

int t = [myId tag];

So, I think the question is: How to get an id of the Label I drew?

And when that works, how to edit the text of the Label ?

I think that when I know how to do these two things, I will be able to find out myself everything else that I want to do in my application.

I'm searching for about three hours, but I think I don't know the right terms to find any relevant info.
Many thanks.

You need to create an outlet in your viewcontroller class and link this to the label. This is a fundamental principle of using interface builder. Xcode 4 can do this automatically for you by using the "assistant" editor ( the little chap with the bow tie) and control-dragging from the label to your class's .h file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM