I have seen many of the posts on this site as well as many more on Google, and I am stuck on what I am sure is something easy. I am new to iOS, and I have most likely been reading the other posts incorrectly. I am trying to learn and write my own code with my own logic and attempts, so mine looks a good deal different than the others I have found... which is why it doesn't work I am sure!
I am trying to get a picture show using swipe from right to left, but I want the next picture to be pulled over and slide into place, instead of the instant switch I have done here. Based on many recommendations, I am trying to use a UIScrollView. I can't get anything to load and the app crashes on the last line of loadImages. I have debugged but can't seem to figure out why it is not showing the subView.
Here is my viewDidLoad:
[super viewDidLoad];
// Do any additional setup after loading the view.
i = 0;
//add UIPanGestureRecognizer
UIPanGestureRecognizer *aPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(loadImages)];
[aPan setMaximumNumberOfTouches:1];
[aPan setMinimumNumberOfTouches:1];
[self.view addGestureRecognizer:aPan];
_PhotoBundle = [[NSBundle mainBundle] pathsForResourcesOfType:@".jpg"inDirectory:@"Otter_Images"];
_PhotoArray = [[NSMutableArray alloc] initWithCapacity:_PhotoBundle.count];
for (NSString* path in _PhotoBundle)
{
[_PhotoArray addObject:[UIImage imageWithContentsOfFile:path]];
}
[self loadImages];
Here is my loadImages:
-(void)loadImages
{ NSLog(@"in loadImages");
_currentImage = [_PhotoArray objectAtIndex:i];
_nextImage = [_PhotoArray objectAtIndex:i + 1];
_prevImage = [_PhotoArray objectAtIndex:i -1];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[scrollView setScrollEnabled:YES];
[scrollView setClipsToBounds:YES];
if (i <= _PhotoArray.count)
{
[scrollView addSubview:_currentImage]; ////crash!!!!
}
else
{
_currentImage = [_PhotoArray objectAtIndex:0];
[scrollView addSubview:_currentImage]; /// Crash!!!!
}
NSLog(@"end of loadImages");
}
I have left off functionality until I can get one image loaded. I will then add the functionality for the slide.... I hope I am approaching this right.
Thank you very much for any help!!
edit:
Here is my interface in my .m that sets up the ImageViews:
@interface ScrollViewViewController ()
@property (nonatomic, retain) NSArray *PhotoBundle;
@property (nonatomic, retain) NSMutableArray *PhotoArray;
@property (nonatomic, retain) UIImageView *currentImage;
@property (nonatomic, retain) UIImageView *nextImage;
@property (nonatomic, retain) UIImageView *prevImage;
@end