iPhone -> Replace UITableView with UITableViewController
I have a ViewController with a nib which have a UIV开发者_运维技巧iew
and a UITableView
. This table view is designed with custom table cells. These table cells has Labels und Textfields.
Now I have the problem that the textfields will disappear under the software keyboard. I read on the Apple Developer pages "Moving Content that is located under the keyboard", that with a UITableViewController
the scrolling will be done automatically and I do not have trouble with scrolling the table view myself:
Note: As of iOS 3.0, the UITableViewController class automatically resizes and repositions its table view when there is in-line editing of text fields. See “View Controllers and Navigation-Based Applications” in Table View Programming Guide for iOS.
So, how can I replace my UIView
-> UITableView
with a UITableViewController
?
What I tried: I put a "Table View Controller" in Interface Builder into the Objects where UIView
-> UITableView
is. Then I delete the UIView
and UITableView
. Then I connect the Table View
under Table View Controller
with the File´s owner which has a property of UITableView.
Running now my app, I get this error:
'-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MyAddView" nib but the view outlet was not set.'
What's the problem here? Can anyone help me?
Thank you in advance & Best Regards.
Update:
MyAddViewController *myAddViewController = [[MyAddViewController alloc] initWithNibName:@"MyAddView" bundle:nil];
UINavigationController *myAddNavigationViewController = [[UINavigationController alloc] initWithRootViewController:myAddViewController];
[myAddViewController release];
[self presentModalViewController:myAddNavigationViewController animated:YES];
-In the last line, the error is thrown.
Don't put a UITableViewController in to the .xib. Make File's Owner be your class, and change your .h file to:
@interface MyTVC : UITableViewController
...
Delete the UIView from the .xib file, leaving only the TableView, and hook up the File's Owner's tableView outlet to the tableView in the .xib.
You may need to exit IB, change the .h file as done above, build the project ignoring errors, open IB, make the above changes, save in IB, then build again in XCode.
精彩评论