使用 addChildViewController 没有调用 UITableViewDatasource 方法没有数据源或委托方法有没有办法解决这个问题?
下面我添加了调用 addChildViewController 方法的父控制器的代码。在下面,我发布了子 viewController 代码(没有 UIViewTableDatasource)
家长代码:
self.commentsController = [[CommentsVC alloc] initWithNibName:@"CommentsVC" bundle:nil restaurant:_resto];
UIView *newview = [[UIView alloc] initWithFrame:self.viewComments.bounds];
self.commentsController.view = newview;
self.commentsController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.viewComments addSubview:self.commentsController.view];
[self addChildViewController:self.commentsController];
子代码
- (id)initWithRestaurant:(Restaurant *)resto{
self = [super init];
if (self) {
_resto = resto;
if(resto.reviews.count == 0){
dispatch_queue_t myQueue = dispatch_queue_create("q_getReviews", NULL);
dispatch_async(myQueue, ^{
id resultReviews = [[RestaurantManager sharedInstance] getRestaurantReviews:resto orderBy:[NSNumber numberWithInt:1]];
dispatch_async(dispatch_get_main_queue(), ^{
if([resultReviews isKindOfClass:[NSError class]]){
NSError *err = (NSError *)resultReviews;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:err.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}else{
self.resto.reviews = (NSMutableArray *)resultReviews;
[((UITableView *)[self.view viewWithTag:kTblComments]) reloadData];
}
});
});
dispatch_release(myQueue);
}
}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
UITableView *tblComments = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
tblComments.tag = kTblComments;
tblComments.delegate = self;
tblComments.dataSource = self;
[self.view addSubview:tblComments];
}