UIScrollView does not work with EXC_BAD_ACCESS

青春壹個敷衍的年華 提交于 2019-12-08 03:52:50

问题


I have a scrollview that is subview of view, and has the subviews. The problem is this: the scrollView came with the black background (as I have set transparent) and also does not work. The scrollView is connected with an IBOutlet. I redid the XIB 2 times, what needs fixing? When I add the scrollView as subview of view:

 [self.view addSubview:self.scrollView];

I get this error during runtime:

   0x132b61:  calll  0x132b66;   CA::Layer::ensure_transaction_recursively(CA::Transaction*) + 14
   EXC_BAD_ACCESS(code=2 address=0xbf7ffffc)

If I do not add it as a subview in the code, the view controller opens and the scrollview is black and does not scroll.


回答1:


Check if you init with your scrollView with frame:

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 280, 360)];

Remember also to set contentSize bigger than frame, for example:

self.scrollView.contentSize = CGSizeMake(2*280, 360);

Also add delegate in your interface:

<UIScrollViewDelegate>

And delegate it:

self.scrollView.delegate = self;



回答2:


You are probably doing somewhere, something like:

[myScrollView addSubview:myAnotherView];
[myAnotherView addSubview:myScrollView];

which kicks an unwanted recursion. Check your code.




回答3:


In my situation I had a UIView that was receiving the same error. In my case I had forgotten to create an IBOutlet for my view. Once I did this, the error went away.



来源:https://stackoverflow.com/questions/13082157/uiscrollview-does-not-work-with-exc-bad-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!