开发者

XCode 4 Interface Builder: How to access a drawn object

开发者 https://www.devze.com 2023-04-10 04:01 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号