Cocoa - Change text of label
I've got a cocoa application that reads in a text file. I'd like开发者_StackOverflow中文版 to display that text in a multi-line label, but I for the life of me can't figure it out. I opened up my .nib file and poped a multi-line label down but after that I'm stuck.
I don't have any experience working with Xcode or Cocoa, mostly Eclipse, Visual Studio, and pretty much every other IDE except Xcode which seems very foreign.
If you have the text in an NSString, you can easily put it in the label.
First, in the .h file (or header) of your controller class, create a new IBOutlet so you can refer to the label:
IBOutlet NSTextField *myLabel;
Go into the .xib file where the label is. Control-drag from the controller object to the label, and select the "myLabel" option to apply it to that specific label.
Then, in the method where you want to put the text in the label, type the following:
[myLabel setStringValue:myString];
(where "myString" is your NSString)
Note: This is all assuming you know how to do basic things like controller classes- if not, I'd definitely check out Cocoa Dev Central (http://www.cocoadevcentral.com/.)
精彩评论