Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AlanMc

macrumors newbie
Original poster
Nov 14, 2012
1
0
Hello!

What I basically want to do, is to set the label of a UITextView outside of a ViewController. Is that possible?

What I have tried is the following:
Code:
@interface myViewController : UIViewController {
    ...
}

@property (nonatomic, retain) IBOutlet UITextView *outputTextField;

@end

and the synthesize code in the .m file.

Then I tried to import myViewController.h in my other .m file and tried to access the TextView like this:
Code:
outputTextField.text = @"test";

This however won't work. What do I need to do differently?

Thank you,
Alan
 
Code:
outputTextField.text = @"test";

This however won't work. What do I need to do differently?

When you say "won't work", what happens exactly? Doesn't do anything? Or doesn't compile? If the latter, what's the error message?
 
Accessing views of one view controller by another view controller is usually a bad idea. If you do it at the wrong time the view won't exist so nothing happens.

Also, this is a violation of MVC design. You should be updating the data model of the view controller and the second view controller should update its view, at the right time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.