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];
}