tags:

views:

191

answers:

2

I've got a cocoa application that reads in a text file. I'd like 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.

A: 

Before going any farther, you should go through some of these tutorials: http://www.cocoadevcentral.com/. They will get you started in a matter of minutes.

drharris
I tried, the tutorial there doesn't work I went step by step and the "Add header to nib" part of the tutorial does not work. When I drag the .h file into the MainMenu.nib box nothing happens.
Nick
When you drag it into the MainMenu.nib box, it does not show up under Classes, as a subclass of NSObject? Be sure to change to list view, and it should be there. If not, what version of XCode are you using? If you're using the latest version (>3.1), it should be finding the classes automatically, no dragging required. If all else fails, these should be more updated tutorials: http://www.cocoalab.com/?q=becomeanxcoder
drharris
Nick: That tutorial shows IB 2, not IB 3. See the note at the top of that tutorial: IB 3 does not require dragging the header into the nib; it detects changes in relevant headers automatically. Skip step 12. Step 13: Drag an Object from the Library into the nib. Steps 14 and 16: A little HUD-styled pop-up will appear where you let go of the mouse button. This replaces the use of the Inspector shown in these steps' screenshots. Step 15: The Palette is dead; long live the Library.
Peter Hosey
+1  A: 

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/.)

Chromium
Unfortunately I don't know about controller classes
Nick
Nick: You (should) have an object that owns the window and all its views, and also the model (at least part of that model being the value you want to display in the label). That object is a controller. The controller class golfromeo is referring to is simply the class of that object. For more info, see the Cocoa Fundamentals Guide: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/
Peter Hosey