0

我处于一个奇怪的情况。我创建了一个nestedViewController,其中单击tableview 中的一行通过调整框架在父嵌套视图的部分标题的标题下方启动另一个nestedviewcontroller。现在,为了向第二个嵌套视图添加不同的功能,我添加了一个 UIViewController(在 tableview 中有自定义单元格)作为 childviewcontroller。现在,当我单击 viewController 的单元格时,不知何故第一个 NestedViewController 的 TableView Delegate 被调用了!!!但是,存在的视图是我作为 childViewController 添加到第二个 NestedViewController 的 UIViewController。

我将 UIViewController 添加到 Second NestedViewController 的方式是:

 DRProductWriteRatingViewController  *writeRatingVC = [[DRProductWriteRatingViewController alloc] initWithNibName:@"DRProductWriteRatingViewController" bundle:nil];
        writeRatingVC.productDict = [productDict mutableCopy];

        newVC = [[DRRatingNestedViewController alloc] initWithFrame:CGRectMake(0,0,320,[UIScreen mainScreen].applicationFrame.size.height-                                                                     COLLAPSED_HEADER_HEIGHT*self.depth) andEntity:childEntity andListing:_listing];
        newVC.category = self.category;
        //            self.depth = self.depth+1;
        dispatch_async(dispatch_get_main_queue(), ^{

            writeRatingVC.tableView.frame = CGRectMake(0,0,320,[UIScreen mainScreen].applicationFrame.size.height-                                                                     COLLAPSED_HEADER_HEIGHT*self.depth-40);
            [newVC.tableView removeFromSuperview];// removing tableview of nestedVC as it is irrelevant
            [newVC addChildViewController:writeRatingVC];
            [newVC.view addSubview:writeRatingVC.view];
            [writeRatingVC didMoveToParentViewController:newVC];
        });

另外,我将第二个 NestedViewController 推到第一个之上的方式是这样的:

- (void)pushViewController:(UIViewController *)viewController {

//1. The current controller is going to be removed
//    [self willMoveToParentViewController:nil];

[viewController willMoveToParentViewController:self];
//2. The new controller is a new child of the container
[self addChildViewController:viewController];

//3. Setup the new controller's frame depending on the animation you want to obtain
CGRect containerRect = CGRectMake(0,  self.view.bounds.size.height ,
                                  320.,
                                  self.view.bounds.size.height - COLLAPSED_HEADER_HEIGHT*(self.depth));
viewController.view.frame = containerRect;
[self.view addSubview:viewController.view];
//    viewController.view.alpha = 0;


//assume that the new view controller is positioned at the bottom of the screen
viewController.view.transform = CGAffineTransformIdentity;
//    CGFloat travelDistance = self.view.bounds.size.height - COLLAPSED_HEADER_HEIGHT - NAVIGATION_BAR_HEIGHT;
CGFloat travelDistance = self.view.bounds.size.height - COLLAPSED_HEADER_HEIGHT - NAVIGATION_BAR_HEIGHT;

if(self.depth>1) {
    travelDistance += NAVIGATION_BAR_HEIGHT;
}

travelDistance += NAVIGATION_BAR_HEIGHT;

if (self.depth >= 2) {
    travelDistance -=NAVIGATION_BAR_HEIGHT;
}

if (self.depth == 5 ) {
    travelDistance -=NAVIGATION_BAR_HEIGHT;
}
CGAffineTransform travel = CGAffineTransformMakeTranslation ( 0, -travelDistance);

[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:kDamping initialSpringVelocity:kInitialSpringVelocity options:0x00 animations:^{
    viewController.view.transform = travel;
    viewController.view.alpha = 1;
} completion:^(BOOL finished) {
    //      self.view.transform = CGAffineTransformIdentity;
    [viewController didMoveToParentViewController:self];
    //mayanktest        [self.tableView reloadData];
}];

}

这里的 Depth 只决定了添加的 NestedVC 的数量。

First Nested VC: DRRatingNestedViewController: 0xd3a9520
Second Nested VC: DRRatingNestedViewController: 0xd0b4f50
Child View to Second Nested VC : DRProductWriteRatingViewController: 0xd0c15b0

所以对象为 0xd3a9520 的 tableViewDelegate 被调用,这是我的问题。

这里应该是什么问题?

4

1 回答 1

0

问题出在 childviewcontroller 框架上。由于框架较小,它能够访问后面的视图。因此,必须在此进行修改:

CGRect containerRect = CGRectMake(0,  self.view.bounds.size.height ,
                              320.,
                              self.view.bounds.size.height - COLLAPSED_HEADER_HEIGHT*(self.depth));
viewController.view.frame = containerRect;
[self.view addSubview:viewController.view];
于 2015-01-07T07:35:22.400 回答