0

I have 3 viewcontroller. FirsViewController, SecondViewController and ThirdViewController. The FirstviewController is root viewcontroller and it is adding secondviewcontrooler xib as the subview. like..

[firstviewcontrollerObject.view addsubview:secondViewcontrollerObj.view].

In secondViewcontroller I have one button. When button touch action is called, ThirdViewController is loaded. like..

[SecondViewControllerobj.view addsubview:thirdviewcontrollerobj.view];

Now ThirdViewCOntroller is on the screen. This viewcontroller has nothing only a small button. So I am seeing 2 buttons on screen. First button is of SecondviewCOntroller and second button is of ThirdViewCOntroller. But, I am able to give touch action of 3rdviewcontroller only not 2ndviewcontroller button.

How should I design my view to take touch of both button and I don't want to merge both controller i one.

4

2 回答 2

0

我认为您应该在不使用多个 UIViewController 的情况下实现它。

视图控制器对于从导航堆栈推送和弹出很有用:一次只显示一个视图。我没有尝试,但我认为这就是你得到这个错误的原因。

但是您更喜欢 navigationControllers 而不是他们的 xib 的好处,不是吗?

如果是这样,有一种方法可以将 xib 与视图一起使用:

NSArray * arr1 = [[NSBundle mainBundle] loadNibNamed:@"MyView1" owner:nil options:nil];
NSArray * arr2 = [[NSBundle mainBundle] loadNibNamed:@"MyView2" owner:nil options:nil];
NSArray * arr3 = [[NSBundle mainBundle] loadNibNamed:@"MyView3" owner:nil options:nil];
UIView * v1 = [arr1 objectAtIndex:0];
UIView * v2 = [arr2 objectAtIndex:0];
UIView * v3 = [arr3 objectAtIndex:0];

// now you have your 3 views, do what you want with them:
v1.center = CGPointMake(100,100);
[self.view addSubview:v1];
v2.center = CGPointMake(100,200);
[self.view addSubview:v2];
v3.center = CGPointMake(100,300);
[self.view addSubview:v3];
于 2012-05-22T10:14:21.427 回答
0

这意味着您的第一个视图控制器包含两个视图,它们来自 secontroller.view 和 thirdviewcontroller.view 现在第三个是按下手势,但第二个不是按下手势。

请在 firstviewcontroller.view 上查看两个视图并这样做

firstviewcontroller.secondVW=[[Secondviewcontroller alloc]init].view;
    firstviewcontroller.thirdVW=[[Thirdviewcontroller alloc]init].view;

以这种方式,两个视图都会发生变化。

于 2012-05-22T10:23:23.187 回答