Note that there are some explanatory texts on larger screens.

plurals
  1. POEXC_BAD_ACCESS when dragging UIScrollView
    primarykey
    data
    text
    <p>In a controller I'm creating a UIScrollView. I'm trying to set this viewcontroller as the UISCrollview delegate and to implement the delegate's method in order to add (later) a UIPageControl.</p> <p>I've read a bit, and found <a href="https://stackoverflow.com/questions/3686803/uiscrollview-exc-bad-access-crash-in-ios-sdk">this link</a>, <a href="https://stackoverflow.com/questions/13082157/uiscrollview-does-not-work-with-exc-bad-access">this other link</a> and other here on SO, and some useful tutorial all around the web, but I don't understand what I'm doing wrong. Everytime a scroll the UIScrollView, the app crashes with an EXC_BAD_ACCESS error.</p> <p>Here's my .h file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface StatsViewController : UIViewController &lt;UIScrollViewDelegate&gt; { UIScrollView *scrollView; UIPageControl *pageControl; } @end </code></pre> <p>Then in my .m file, I'm creating the scrollview and trying to define the delegate method like this:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSInteger boxWidth = self.view.frame.size.width; NSInteger boxHeight = 412; scrollView = [ [UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, boxHeight)]; scrollView.pagingEnabled = TRUE; scrollView.delegate = self; NSInteger numberOfViews = 2; StatBreatheCounter *breatheCounter = [ [StatBreatheCounter alloc] init]; breatheCounter.view.frame = CGRectMake(0, 0, boxWidth, boxHeight); [scrollView addSubview:breatheCounter.view]; BreatheLocationViewController *breatheLocation = [ [BreatheLocationViewController alloc] init]; breatheLocation.view.frame = CGRectMake(320, 0, boxWidth, boxHeight); [scrollView addSubview:breatheLocation.view]; scrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, boxHeight); [self.view addSubview:scrollView]; </code></pre> <p>}</p> <pre><code> - (void)scrollViewDidScroll:(UIScrollView *)sender { NSLog(@"RUNNING"); } </code></pre> <p>...but every time I slide on the scroll view, the app is crashing. Now, I'm quite a n00b on Ojective-C, but I feel I'm missing something. Browsing around everything points on the fact that the delegate could be deallocated early, and when the user trigger the action, no one is handling the method (sorry for the explanation :)). ...but if the delegate it's the viewcontroller itself, how could it be deallocated?</p> <p>As you can see, I'm quite confused :( Any help would be really appreciated</p> <p>-- EDIT: I'm going to include here the solution founded thanks with your comments and answer. When I posted my question I was so convinced that the error was coming from the way I was creating the UIScrollView and setting its delegate that I didn't realize that the problem was (as everything was suggesting, btw :)) I was allocating the StateViewController in its parent without declaring any "strong" reference to it (again, sorry for the explanation, I'm really a n00b in this). Thanks a lot for your helping in pointing me on the right direction</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload