我在UIViewController子类中创建了一个UITableViewController并设置了委托方法,但数据源委托方法没有被调用(通过观察日志)。我是否需要继承UITableViewController?我错过了什么?UITableView委托方法不被调用
在MyViewController.h
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableViewController *myTableViewController;
}
@property (nonatomic, assign) UITableViewController *myTableViewController;
在MyViewController.m
- (void)viewDidLoad
{
myTableViewController = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
myTableViewController.tableView.delegate = self;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
NSLog(@"numberOfRowsInSection");
return [self.assets count]; //assets is NSMutableArray
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [assets objectAtIndex:row]; //assets is NSMutableArray
cell.textLabel.font = [UIFont boldSystemFontOfSize:50];
return cell;
}
我称为从另一个类表视图:
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myTableViewController];
虽然我没有与您的解决方案,但在UITableViewDataSource良好的纠正。 – user523234