ios - using addChildViewController the UITableViewDatasource methods are no being called -


using addchildviewcontroller uitableviewdatasource methods no being called none of datasource or delegates methods there way solve this?

bellow have added code of parent controller calling addchildviewcontroller method. , bellow that, posted child viewcontroller code (whithout uiviewtabledatasource)

parent code:

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

child code

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

  1. in parent code calling [[commentsvc alloc] initwithnibname:@"commentsvc" bundle:nil restaurant:_resto]; initializing child view controller, in child view controller loading data suppose using table view it's possible data source empty.

  2. it's call [((uitableview *)[self.view viewwithtag:ktblcomments]) reloaddata]; in init method, table view not initialized yet.

so make sure calling right init methods child view controller , make sure table view data source not empty , after can call [yourtableview reloaddata] after init table view, set it's delegate , add subview.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -