2

I have Objective C code that continually updates a set of numerical values. I need to display these values on the screen. That's it! I can convert numerical values into a text string, no problem. But how do I display this string in a UI element? Do I use a text box or a text field or a text view, or a...? I cannot find examples to show how to pass a string from code into the UI. I assume I need to set up a text thingy, and then periodically refresh the contents of that text thingy when the values change?

I assume the answer is simple but is just obscured by a smokescreen of technical jargon.

Thanks!

3
  • Do you have any kind of interface created through code or the interfacebuilder / storyboard? If the later one is the case: connect the UITextField, or UITextView or UILabel as IBOutlet to your code.
    – luk2302
    Mar 25, 2015 at 18:15
  • Hi luk2302 - that sounds like the kind of answer I'm looking for :) I do have a .xib file and can drop-in UI elements. I have used IBOutlet before, and I can refer to that pattern. I'll give that a try. Thanks! -j
    – user4586083
    Mar 25, 2015 at 18:46
  • You are welcome, there are plenty of tutorials out there for that purpose, since it is one of the most basic interface builder operations, have a look at raywenderlich.com or just plain old youtube ;)
    – luk2302
    Mar 25, 2015 at 18:48

1 Answer 1

2

From the UI perspective you might want something like a

  • UITextView - multi-line text input
  • UITextField - single-line text input
  • UILabel - just text

For your purpose of just printing text, you should use UILabel, since you dont want / need any kind of input. You can access its text using:

// yourLabel is your current UILabel* you want to output yourValue to
yourLabel.text = yourValue;

Of course that yourValue needs to be converted to NSString before.

To actually get hold of the UILabel, you need to connect it from the Interface Builder as an IBOutlet. For tutorials on that topic, take a look at tutorials like Interface Tutorials by Ray Wenderlich or youtube or just google Interface Builder tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.