Strange behavior of a UITableViewController
I'm creating an application (TabBar based) and I'm adding in the first view an UINavigationController
with a UITableViewController
as its rootViewController.
In the documentation I read that a TableView
owned by a UITableViewController
, if not stated differently, has as delegate
and dataSource
his own tableViewController.
The problem is that the methods of the two protocols (UITableViewDelegate
, UITableViewDataSource
) are never called (figured out using NSLog()
).
I know I've made an error at some point, can't understand where.
I'm not sure if I understand you question correctly but here's a rough guess.
Have you set your datasource and delegate for your UITableView like somewhere in your viewDidLoad method?
Like say you got something declared like this:
@interface MyViewController <UITableViewDelegate,UITableViewDataSource>
{
UITableView *myTableView;
}
@property (nonatomic, retain) UITableView *myTableView;
@end
In your viewDidLoad method in the implementation file, you should have something similar like:
-(void) viewDidLoad
{
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[myTableView setDelegate:self]; //this view controller (MyViewController) will be the delegate
[myTableView setDataSource:self]; // data will come from this view controller itself
...
[super viewDidLoad];
}
Is that what you were after?
精彩评论