Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here are some ways to overcome obstacles in iOS development:</p> <ol> <li><p>Look at the documentation for the particular class you're trying to manipulate. In this case, <code>UITextView</code> documentation can be found within Xcode or <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextView_Class/Reference/UITextView.html">online</a>. </p></li> <li><p>Command-Click on <code>UITextView</code> or any other object anywhere in your code, and it will bring you to the header file for that class. The header file will list every public method and property. </p></li> <li><p>Look at your existing code. I'm assuming that since you have a button that adds text to a <code>UITextView</code>, you understand how to set its text. 99% of the time you'll find that any setter (mutator) methods will have a corresponding getter (accessor) method. In this case, <code>UITextView</code> has a method called <code>setText:</code> and a matching method just called <code>text</code>. </p></li> </ol> <p>Finally, <code>NSString</code> has a convenience method called <code>stringWithFormat:</code> that you can use to concatenate (join) two strings, among other very useful things. <code>%@</code> is the format specifier for a string. For example, to combine two strings, <code>stringOne</code> and <code>stringTwo</code>, you could do the following:</p> <p><code>NSString *string = [NSString stringWithFormat:@"%@ %@", stringOne, stringTwo];</code></p> <p>I will leave you to come up with the answer as to how to combine <code>NSString</code> <code>stringWithFormat:</code> and <code>UITextField</code> <code>text</code> and <code>setText:</code> to achieve what you'd like to accomplish. </p> <hr> <p><strong>Edit:</strong> <em>The OP was unable to figure out how to utilize the information above so a complete code sample has been provided below.</em></p> <p>Assume you have synthesized property (possibly an <code>IBOutlet</code>) <code>UITextView</code> that you have initialized called <code>myTextView</code>. Assume also that we are currently in the method scope of the method that gets called (your <code>IBAction</code>, if you're using IB) when you tap your <code>UIButton</code>.</p> <pre><code>[myTextView setText:[NSString stringWithFormat:@"%@ %@", myTextView.text, @"this is some new text"]]; </code></pre> <p>Explanation: <code>myTextView.text</code> grabs the existing text inside of the <code>UITextView</code> and then you simply append whatever string you want to it. So if the text view is originally populated with the text "Hello world" and you clicked the button three times, you would end up with the following progression:</p> <p>Initial String: @"Hello world"<br> Tap one: @"Hello world this is some new text"<br> Tap Two: @"Hello world this is some new text this is some new text"<br> Tap Three: @"Hello world this is some new text this is some new text text this is some new text"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload