Search code examples
objective-caddsubview

Objective C addSubview elements are not clickable


I Have a horizontal UIScrollView. I want to do a magazine app. I create a dynamic UIview as this:

UIView *one=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*4, 0, 0, 0)];

and my view:

pageOneViewController *pageOne=[[pageOneViewController alloc]init];

and then:

[one addSubview:pageOne.view];
[self.scroll addSubview:one];

with these codes, the elements that in pageOneViewController, can not clickable.

if I add "pageOneViewController.view" directly to the self.scroll they can.

how can I make clickable with first situation?


Solution

  • Here in your code

      UIView *one=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*4, 0, 0, 0)];
    

    Here width and height are 0, try to set background color and non zero values for height and width for view and check your view in scrollView.

      pageOneViewController *pageOne=[[pageOneViewController alloc]init];
    
      // Y value as per your need, I have set 0.
      UIView *one=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*4, 0, pageOne.view.frame.size.width, pageOne.view.frame.size.height)];
      [one addSubview:pageOne.view];
      [self.scroll addSubview:one];