2

hi i'm studying iOS programming.

i have a trouble to use UITextView.

i made a project and open viewController.xib

i dragged in UISearchBar, UITextView and UILabel

and my viewController is followed UISearchBarDelegate

i want to change textView.text's contents but it doesn't.

here's my code.

-(void)viewDidLoad
{
   [super viewDidLoad];
   self.mySearchbar.delegate = self;
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    self.myLabel.text = @"hoho";
    self.myTextview.text = @"hoho";
}

when i clicked search bar and typing any character and return,

myLabel's text is set to hoho.

but myTextview.text doesn't set. no effect.

why is that?? i'm confused.. please help me

1
  • have u connect ur IBOutlet UITextView *myTextView object to its XIB instance. May be that would be problem Commented Apr 18, 2012 at 4:29

4 Answers 4

7

Did you link up the Outlet in Interface Builder? In IB, click File's Owner, select Outlets on the right pane, link myTextview to the UITextview you put on the view?

Also, since you are calling "self" I assume you created a property for myTextview as an IBOutlet in your .h file?

Sign up to request clarification or add additional context in comments.

2 Comments

oops. what a fool mistake... :(
@MoonSoo: Forgetting to connect XIBs and outlets are one of the most annoying mistakes that many developers make frequently. It causes no end of grief when it happens. :)
0

Are you setting(connecting) the delegate of UITextView as well. That might be the problem.

Comments

-1

Try to set the TextView Color to black

[YourTextview setTextColor:[UIColor blackColor]];

Sometimes this helps.

Comments

-3

As I recall, instead you should be using

[self.myLabel setText:@"hoho"];

4 Comments

No, they are exactly equivalent. The OP is merely using properties instead.
@sudorm-rf "The OP is merely using properties instead." Actually the compiler compiles dot-syntax down to accessors and mutators (text, setText:, etc).
myLabel.text = xxx is the exact same as [myLabel setText:xxx]. It's simply a style preference on which to use.
@JackLawrence: Thanks for clarifying the terminology.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.