在自定义UITableViewCell的子视图中添加UIViewController

时间:2016-02-18 07:14:39

标签: ios objective-c uitableview

我有一个带XIB的自定义UITableViewCell。它有一个webview和名为slideShow的UIView。我只想在slideShow UIView组件中添加自定义uiviewcontroller。在这样做的时候,当我添加了ChChildViewController时,它就崩溃了。

我可以将此ViewController添加为self.view中的子视图。但是无法在自定义tableviewcell中添加视图

请帮助..

    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 个答案:

答案 0 :(得分:0)

首先在CellForRow中设置UIView的nib,就像那样

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