0

I'm having a problem with setText method for UITextView.

As I said on the title, I tried to change a UITextView text by using setText method or change the text property directly. It only works from the second time since the method is called.

My UITextView was an outlet. I even tried to change it's text directly from the owner class or create a method to call from another class, but it behaves the same.

I dont know if I'm doing sth wrong when create it as an outlet, I also tried to set it as nonatomic, strong, weak, retain but I still can't get it.

Any advice for my case? Thanks in advance! :)

EDIT: I figured it out from David H's answer.

As my app is using tab, first tab is used for searching words, the second one for displaying the meaning, I tried to set the text before the outlet is created (as I haven't clicked the second tab yet). If I click the tab meaning first in order to let the outlet to be created, then it works perfectly.

Thanks for all the answer!

4

1 回答 1

1

几乎可以肯定,您第一次尝试设置它时,出口为零 - 尚未设置。所以在你设置它之前添加一个断言(assert(myTextView),或者至少添加一个 NSLog 消息。你肯定会在第一次尝试时发现 textView 为 nil。

于 2013-05-30T16:42:17.400 回答