Handling UITextView Data inside a Table View
i have this MainViewController, which is a controller for my table view. Whenever I press a row on the table view i go to my employeeViewController. Which is a normal view with a Text View inside 开发者_StackOverflow中文版of it.
So my hierarchy looks like this:
-Window
--Navigation Controller
---Navigation Bar
---Main View Controller
----Table View
----Navigation Item
And whenever i press a row in the list, based on the value of a given key, i get a view opened called employeeViewController.xib. His viewController is called the same, employeeViewController.h (as specified in the File's Owner object.)
So, i've added the following items to the view, with the following hierarchy:
-View
--Text View
I've linked the Text View's delegate and referencing outlets to the file's owner. And the files owner is also linked to the View, for the 'view' referencing outlet.
So when i try the following in my employeeViewController.m my TextView does not respond:
- (id)initWithNibAndEmployeeName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil employeeName:(NSString *)employeeName {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
name = employeeName;
textView.text = name;
}
return self;
}
And this is my employeeViewController.h:
@interface employeeViewController : UIViewController <UITextViewDelegate> {
NSString *name;
IBOutlet UITextView *textView;
}
-(id)initWithNibAndEmployeeName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil employeeName:(NSString *)employeeName;
@end
Why can't i do anything with my TextView using this set up?
Thanks in advance!
"Lazy loading" is the problem - anything in your view is allocated and initialized until view is about to appear, so you will be able to set value to textView only in viewWillAppear method.
精彩评论