0
votes

I have a custom UITableViewCell with XIB. It has a webview and UIView named slideShow. I just want to add a custom uiviewcontroller inside slideShow UIView component. While doing that, when i addChildViewController, it is crashing.

I'm able to add this ViewController as a subview in self.view. But not able to add in a view inside custom tableviewcell

Please help..

    self.homePageCell = (SSHomePageCell *)[tableView dequeueReusableCellWithIdentifier:@"SSHomePageCell"];

     if (self.homePageCell == nil)
     {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SSHomePageCell" owner:self options:nil];
    self.homePageCell = [nib objectAtIndex:0];
     }

    self.imageShow = (ImageSlideShowViewController *) [storyboard instantiateViewControllerWithIdentifier:@"ImageSlideShow"]; 
    self.imageShow.view.frame = CGRectMake(0, 0, self.homePageCell.imageSlideShowContainerView.frame.size.width, self.homePageCell.imageSlideShowContainerView.frame.size.height); 
    self.imageShow.title = self.title;

 [self addChildViewController:self.imageShow];

 [self.homePageCell.imageSlideShowContainerView addSubview:self.imageShow.view]; 

 [self.imageShow didMoveToParentViewController:self];

    return self.homePageCell;
1
use uicontainer view in cell, it's easy to add uiviewcontroller in viewNANNAV
Please show us the code you used to try to make it workthxou
self.imageShow = (ImageSlideShowViewController *) [storyboard instantiateViewControllerWithIdentifier:@"ImageSlideShow"]; self.imageShow.view.frame = CGRectMake(0, 0, self.homePageCell.imageSlideShowContainerView.frame.size.width, self.homePageCell.imageSlideShowContainerView.frame.size.height); self.imageShow.title = self.title; [self addChildViewController:self.imageShow]; [self.homePageCell.imageSlideShowContainerView addSubview:self.imageShow.view]; [self.imageShow didMoveToParentViewController:self]; return self.homePageCell;rkr_stack
please check my updated ansRohit Pradhan

1 Answers

0
votes

First You set nib of UIView In CellForRow Like that

UIView *View = [[[NSBundle mainBundle] loadNibNamed:"UIView Name" owner:self options:nil] objectAtIndex:0];

View.frame = CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height);

[self.view addSubview:View];