简体   繁体   English

在UIView内部创建的UIButton是scrollview的子级

[英]UIButton created inside UIView which is child of scrollview

I am creating UIScrollView on main view, then I am creating UIView which is child of UIScrollView and creating UIButton which is child of UIView . 我创建UIScrollView的主视图,然后我创建UIView这是孩子UIScrollView和创造UIButton这是孩子UIView

When I am calling next ViewController on touch up inside event occur,first time it is taking time to load next view controller and second time not. 当我在内部触摸事件上调用下一个ViewController时,第一次是花时间加载下一个视图控制器,而第二次则不是。

Flow:- 流:-

Main View -> scroll View -> uiview -> uibutton 主视图->滚动视图-> uiview-> uibutton

Below is the solution 下面是解决方案

in viewDidLoad method of FirstViewController 在FirstViewController的viewDidLoad方法中

[subView addSubview:btn];
[scrollView addSubview:subView];
[self.view addSubView:scrollView];

Then Button Action Method 然后按钮动作方法

-(IBAction)actionGo:(id)sender
{
  NextViewController *nextVC = [NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
  [self.navigationController pushViewController:nextVC animated:YES];    
}

in NextViewController.m 在NextViewController.m中

-(IBAction)actionBack:(id)sender
{
  [self.navigationController popViewControllerAnimated:YES];
}

In first time when you run ViewController it unpacked data from XIB/Storyboard. 第一次运行ViewController时,它会从XIB / Storyboard解压缩数据。 This operation is taking some time. 此操作需要一些时间。 All other times when you call methods on you controller it will be cached and call immediately. 在您调用控制器上的方法的所有其他时间,它将被缓存并立即调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM