Changing the text in a UITextView at runtime - iphone

I have a ViewController consisting of just a textView. In its viewDidLoad method, I simply initialize the textView and add it as a subview. In my main ViewController class, when the user presses a button, I switch views and display the view that has the textView. I am trying to change the textView's text however it is not working. Can I not change the text of a UITextView at runtime?
Thanks.

You should keep a reference to your text view.
If you do, then make sure that the reference is correct and valid before setting the new text.
In general, it always helps when you post a problematic code - this way it is much easier for us to help you...

Related

Updatable, custom view on a UIToolbar

I want to make a small area to present some information in the middle of a UIToolbar and was wondering what the best way to do this is.
I need to show some text and a graphic, both of which need to be updated (around every 3 seconds) as new information arrives. The graphic is similar to the iPhone signal strength indicator, so it can be either custom drawn or selected from one of 3 graphics (low, medium, high strength).
I'll probably use initWithCustomView: to create a UIBarButtonItem, although I would like the view to be clickable (to allow the user to change the information shown).
What's the best way to make that view? Can I use a NIB, or do I need to do custom drawing in the view? What's the best way to update the buttons? I'm assuming that I'll have to remake the toolbarItems array each time and set it when the information changes. Is there a cleaner way to do this? Thanks.
Using initWithCustomView: sounds like a good way to go. You can create your custom view any way you want: with a NIB, by drawing it, even using images. It can also have its own subviews. It can be any object that inherits from UIView. (So, if you wanted, you could even make it actionable by using a UIButton, a custom UIControl, or a custom UIView with a gesture recognizer attached.)
You shouldn't have to remake toolbarItems (or, for that matter, do anything with it after you've added all your button items) if you just keep a pointer to your custom view UIBarButtonItem. It could be an instance variable. Then, to update the custom view, you could access it as you would any other view. I've never actually tried this, but I can't see any problem with doing it.
You sound like you had it mostly figured out. Hope this is helpful.
I needed the same solution and was hoping for some code examples from you. So I ended up doing it all in IB and the steps are here as follows:
Create UItoolbar in IB with no Items. (A Bar Button Item will be added again once you add the UIView)
Add UIView as subview of UIToolbar
Add UILabels to subview of UIView that is already a subview of the UIToolbar.
Create IBOutlets from UIToolbar, UIView and each UILabel and then you can reference the labels in your app.
I did set the backgrounds to clearColor so the text appears on top of UIToolbar without any box or borders.
And the text updates dynamically which was the desired outcome.
Hope this helps someone as this has been eluding me for a while.

Focus and zoom in on a UITextField when touched?

How in the world does one get the iPhone view to zoom in on a focused UITextField? I need to tap on a text field that I want to edit, and my view should zoom in to the tapped text field and pull up the keyboard (which it already does), similar to how many Internet text fields gain focus on the iPhone. Is this some type of overlay?
I've been looking everywhere for this solution but maybe I've just got the wrong terminology. Thank you in advance.
Could be a duplicate of this StackOverflow question.
In essence, there are a number of ways, but you have to program this effect manually. A textfield is already an overlay. You can either move it, or scroll the containing view.
Please follow the following steps.
Implement the delegate method for all textfield.connect the outlet of textfield in interface builder basically it's setting the delegate property.then in delegate property you can defined the method whatever you want to implement or wanted to do functionality.
Thanks

iPhone UIImage overlapping text

I have a view with a UIScrollView, UIImageView for a background, and a UITextView. I have created several other views just like this and they all come out okay - with a background image and scrollable text but for some reason, now I can't make that work. Either my image overlaps all of the text so that I can't read it or the UITextView default background (white) shows up so that the user can't see the background image. What could be causing this problem?
Do you use Interface Builder or build the views hierarchy in code?
In both cases you should make sure that the order of your views is correct.
In IB the view that you want to appear on top of all the rest has to be under the rest of the views.
In code, make sure that the text view is the last to be added to the hierarchy.
You could also use the next code in order to check if this is the problem:
[self.view bringSubviewToFront:textView];
Okay, it must have had something to do with choosing the delegate. I can't say that I completely understand how I fixed it but it had to do with declaring the delegate in IB.

UITextView in UITableViewCell scrolling problems

Ok. I have made a custom cell for my table, and it contains a text view. When I have multiple lines in the text view, I can scroll up and down, but in doing this the table also scrolls. How can I stop this behaviour? If anyone needs parts of my code or further details, please just ask. I am more than willing.
Thank you for your help
I suggest you to move text edit (write) behavior to another view controller. If you need read-only functionality from it then just increase cell and textView height.
Did you try setting canCancelContentTouches to NO? It's a property of UIScrollView, from which UITableView inherits.
Your custom cell seems to pass on touch events to its container class as well as utilizing them itself. Did you implement any - touchesBegan:, - touchesMoved: or - touchesEnded:?
If you make use of a touch events, you should not pass them on in the responder chain.
When the text view has focus, set scrollEnabled=NO on the table view. You may have to manually remove focus from the text view and restore scrolling when a touch occurs outside the text view.

iphone copy/paste menu not shown in UITableViewCell

I placed a UITextField and a UITextView in a tableviewcell. When tap on text in them, it allows me to enclose a portion of the text with a rectangular popup showing the enclosed text enlarged. I want to either copy or paste over the selected text, but the copy-paste menu never show up whether I single tap, double taps or press and hold. I appreciate any hints you can give.
Somehow the copy/paste menu starts showing up when I tap the textfield or textview. Not clear on what I have done that made the difference. But I can tell you what I did for your reference. I tried to married NIB file, Custome UIViewController, UITableViewCell into one. I had the textfield and textview embeded in a UIViewController. The UIViewController userinterface is loaded from a NIB file. I then have the UIViewController view added as a subview into the tableViewCell. You can do some googling on this. There are many suggestions.
I do agree with some people who advice not to load NIB into an UITableViewCell. In the end, I took the advice and coded the user interface entirely without the NIB file. I declared a subclass of UITableViewCell then had thd user interface constructed within the initWithStyle. This way the custom tableViewCell was readily useful in the tableView without the headache of figuring out how to load the NIB file and how to make the UIViewController reuseable as a tableViewCell.
Since the code was a lot cleaner, I probably accidentally removed the bad code that had broke the copy/paste mechanism.