UIScrollView: Crash on Dragging

Discussion in 'iOS Programming' started by Sergio10, Jan 23, 2010.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,

    I've implemented custom UIScrollView with images. But on dragging it crashes.
    Here is a code:
    PHP:
    const CGFloat kScrollObjHeight   100.0;
    const 
    CGFloat kScrollObjWidth    100.0;
    const 
    NSUInteger kNumImages      7;

    - (
    void)viewDidLoad {
        
        
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];    
        [
    _scrollView setBackgroundColor:[UIColor whiteColor]];
        [
    _scrollView setCanCancelContentTouches:NO];
        
    _scrollView.indicatorStyle UIScrollViewIndicatorStyleWhite;
        
    _scrollView.clipsToBounds YES;        // default is NO, we want to restrict drawing within our scrollview
        
    _scrollView.scrollEnabled YES;
        
    _scrollView.minimumZoomScale 1;
        
    _scrollView.maximumZoomScale 3;
        
    _scrollView.delegate self;
        [
    _scrollView setScrollEnabled:YES];    
        [
    _scrollView setContentSize:[self loadImagesFromBundle]];    
        
    _scrollView.pagingEnabled YES;
    }

    // load all the images from bundle 
    // and add them to the scroll view
    - (CGSize)loadImagesFromBundle {
        
        
    CGSize contentSize;
        
    contentSize.height kScrollObjHeight;
        
    contentSize.width 0;    
        const 
    int kGap 20;  
        
        for (
    int i 1<= kNumImagesi++)
        {
            
    NSString *imageName = [NSString stringWithFormat:@"photo%d.png"i];
            
    UIImage *image = [UIImage imageNamed:imageName];
            
    UIImageView *imageView = [[UIImageView allocinitWithImage:image];
            
            
    // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList" 
            
    CGRect rect imageView.frame;

            
    rect.size.height kScrollObjHeight;
            
    rect.size.width kScrollObjWidth;
            
    rect.origin.contentSize.width;
            
    rect.origin.kGap;
            
            
    contentSize.width contentSize.width kGap kScrollObjWidth;
            
            
    imageView.frame rect;
            
    imageView.tag i;    // tag our images for later use when we place them in serial fashion
            
    [_scrollView addSubview:imageView];
            [
    imageView release];
        }    
        
        return 
    contentSize;
    }
    PHP:
    @interface ScrollViewController UIViewController <UIScrollViewDelegate> {

        
    IBOutlet UIScrollView *_scrollView;
    }

    - (
    CGSize)loadImagesFromBundle;

    @
    property (retainUIScrollView_scrollView;
    @
    end
    Where is a mistake?

    Thank you.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    This statement is far too vague for us to help diagnose. You need to determine the cause of the crash. For example, have you tried checking the crash logs to see what they say?
     
  3. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #3
    Here is a crash report:
     

Share This Page