Looping through on NSArray objects with button taps - ios

I have an array of NSStrings, what I'd like to use as a source for a UIImageView's image names.
When the user taps a button I load a new image - next object from the array - into the same image view, that would be the final goal. Actually I have a working, but silly solution, and that's not what I want. I would like to load the string names from an array to the UIImage, because this if statement can grow really big with 30-40 object and that's not so reliable. I'm not so fine with for loops so I would really appreciate if somebody could show me how can I get the same result with a loop or any other way.
- (IBAction)changeImage:(id)sender {
if (!self.userImageView.image) {
UIImage *image = [UIImage imageNamed:#"img1.png"];
self.userImageView.image = image;
self.currentDisplayedImageString = #"img1.png";
// self.currentDisplayedImageString is an ivar, type of NSString
}
else {
if ([self.currentDisplayedImageString isEqualToString:#"img1.png"]) {
UIImage *image = [UIImage imageNamed:#"img2.png"];
self.userImageView.image = image;
self.currentDisplayedImageString = #"img2.png";
}
if ([self.currentDisplayedImageString isEqualToString:#"img2.png"]) {
UIImage *image = [UIImage imageNamed:#"img3.png"];
self.userImageView.image = image;
self.currentDisplayedImageString = #"img3.png";
}
// AND SO ON...
}
}

something like:
#interface ViewController ()
#property (strong, nonatomic) UIImageView *imageView;
#property (strong, nonatomic) NSArray *imageNames;
#property (assign, nonatomic) int currentImageIndex;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.imageNames = #[#"img1", #"img2", #"img3", #"img4"];
self.currentImageIndex = -1;
}
- (void)changeImage {
if (++self.currentImageIndex == self.imageNames.count) {
self.currentImageIndex = 0;
}
self.imageView.image = [UIImage imageNamed:self.imageNames[self.currentImageIndex]];
}
#end
hope it helps!

If your image names are in fact "img1," "img2," "img3," etc. you don't actually need an array to store them since the names essentially index themselves. Instead I'd recommend doing something like:
- (IBAction)changeImage:(id)sender {
if (!self.userImageView.image ||
[self.currentDisplayedImageString isEqualToString:#"img40.png"]) {
self.currentDisplayedImageString = #"img1.png";
}
else {
// Get the filename's numerical index by parsing out the numerical component
NSString *index = [[self.currentDisplayedImageString componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:#""];
// "Increment" the currentDisplayedImageString
self.currentDisplayedImageString = [NSString stringWithFormat:#"img%#.png", index];
}
// Then update the image
UIImage *image = [UIImage imageNamed:currentDisplayedImageString];
self.userImageView.image = image;
}

Related

how to select the images differently from array using objective-c

I have store 10 images in NSArray.
In UIViewController i placed 6 UIImageView,and given the outlet in .h file.
I need to select any 6 images from the array how to do?
And need to display the images in UIImageView.
- (void)viewDidLoad {
[super viewDidLoad];
images=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:#"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:#"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:#"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:#"tree.jpg"],[UIImage imageNamed:#"luxury-christmas-napkins-father-christmas-1635-p.jpg"],[UIImage imageNamed:#"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:#"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:#"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:#"tree.jpg"],[UIImage imageNamed:#"luxury-christmas-napkins-father-christmas-1635-p.jpg"], nil];
NSString *dd=[NSString stringWithFormat:#"%#", images];
NSLog(#"%#",dd);
}
- (void)setImagesForImageViews:(NSArray<UIImageView*>*)viewsArray fromArray:(NSArray<UIImage*>*)imageArray {
if(images == nil || viewsArray == nil || viewsArray.count > images.count) {
return; // early return
}
NSMutableArray* randomImageArray = [NSMutableArray arrayWithCapacity:viewsArray.count];
while (randomImageArray.count < viewsArray.count) {
UIImage* image;
do {
NSUInteger random = (NSUInteger)arc4random_uniform(images.count);
image = [imageArray objectAtIndex:random];
} while ([randomImageArray containsObject:image]);
[randomImageArray addObject:image];
}
[viewsArray enumerateObjectsUsingBlock:^(UIImageView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.image = [randomImageArray objectAtIndex:idx];
}];
}
in .h file
#import
#interface memory_test : UIViewController
{
NSMutableArray *images;
}
#property(weak,nonatomic)IBOutlet UIImageView *b1;
#property(weak,nonatomic)IBOutlet UIImageView *b2;
#property(weak,nonatomic)IBOutlet UIImageView *b3;
#property(weak,nonatomic)IBOutlet UIImageView *b4;
#property(weak,nonatomic)IBOutlet UIImageView *b5;
#property(weak,nonatomic)IBOutlet UIImageView *b6;
Lets suppose(as the question is not clear), you want to set random images to imageviews from an array of images. The challenge here is to find the random image, non-repeating, ofcourse from an array.
I haven't tested the code, but something like this should work:
- (void)viewDidLoad {
[super viewDidLoad];
NSArray* images = [self imagesArray];
NSArray* views = [self imageViewsArray];
[self setRandomImagesForImageViews:views fromArray:images];
}
- (NSArray<UIImage*>*)imagesArray {
return #[[UIImage imageNamed:#"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:#"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:#"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:#"tree.jpg"],[UIImage imageNamed:#"luxury-christmas-napkins-father-christmas-1635-p.jpg"],[UIImage imageNamed:#"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:#"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:#"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:#"tree.jpg"],[UIImage imageNamed:#"luxury-christmas-napkins-father-christmas-1635-p.jpg"]];
}
- (NSArray<UIImageView*>*)imageViewsArray {
return #[_b1, _b2, _b3, _b4, _b5, _b6];
}
- (void)setRandomImagesForImageViews:(NSArray<UIImageView*>*)viewsArray fromArray:(NSArray<UIImage*>*)imageArray {
if(imageArray == nil || viewsArray == nil || viewsArray.count > imageArray.count) {
return; // early return
}
NSMutableArray* randomImageArray = [NSMutableArray arrayWithCapacity:viewsArray.count];
while (randomImageArray.count < viewsArray.count) {
UIImage* image;
do {
NSUInteger random = (NSUInteger)arc4random_uniform(imageArray.count);
image = [imageArray objectAtIndex:random];
} while ([randomImageArray containsObject:image]);
[randomImageArray addObject:image];
}
[viewsArray enumerateObjectsUsingBlock:^(UIImageView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.image = [randomImageArray objectAtIndex:idx];
}];
}
You can remove your images array declaration from your header file if you are not using it again in the class.
FOR SWIFT
class ViewController: UIViewController {
//array with ImageView
#IBOutlet var imageViews: [UIImageView]!
//array with Image
lazy var imagesArray = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
//initiate image
let imageOne :UIImage = #imageLiteral(resourceName: "exchange")
let imageTwo :UIImage = #imageLiteral(resourceName: "indexPhone")
let imageThree :UIImage = #imageLiteral(resourceName: "indexCheer")
let imageFour :UIImage = #imageLiteral(resourceName: "indexTrade")
let imageFive :UIImage = #imageLiteral(resourceName: "indexWashMachine")
//add image to array
imagesArray = [imageOne,imageTwo,imageThree,imageFour,imageFive]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Action for Button
#IBAction func randomSelect(_ sender: Any) {
//temporary array for images
var tempImageArray = imagesArray
for imageView in imageViews{
// get random index for array images
let index = Int(arc4random_uniform(UInt32(tempImageArray.count)))
// set random image for ImageView
imageView.image = tempImageArray[index]
// remove arleady added Image from temporary array
tempImageArray.remove(at: index)
}
}
}
FOR OBJECTIVE-C
#interface ViewController ()
//array with ImageView
#property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *imageViews;
//array with Image
#property (strong, nonatomic) NSArray* imagesArray;
- (IBAction)randomSelect:(id)sender;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//initiate image
UIImage *imageOne = [UIImage imageNamed:#"exchange"];
UIImage *imageTwo = [UIImage imageNamed:#"indexCheer"];
UIImage *imageThree = [UIImage imageNamed:#"indexPhone"];
UIImage *imageFour = [UIImage imageNamed:#"indexTrade"];
UIImage *imageFive = [UIImage imageNamed:#"indexWashMachine"];
//Initiate array with image
self.imagesArray = [NSArray arrayWithObjects:imageOne,imageTwo,imageThree,imageFour,imageFive, nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)randomSelect:(id)sender {
//temporary array for images
NSMutableArray* tempImageArray = [[NSMutableArray alloc]initWithArray:self.imagesArray];
for (UIImageView* imageView in self.imageViews){
// get random index for array images
int index = arc4random()%(tempImageArray.count-1);
// set random image for ImageView
imageView.image = [tempImageArray objectAtIndex:index];
// remove arleady added Image from temporary array
[tempImageArray removeObjectAtIndex:index];
}
}

Resizing an image before uploading to server on iOS

I'm trying to resize an image in a photo app and haven't been successful yet. I'm new to photo resizing on iOS, but I swear that I'm doing this right, but my logs show:
Error: <WUTModelImageUploadReq>
[photo]: <nil>
[extension]: <nil>
</WUTModelImageUploadReq>
I'm trying to set 'scaleImage' as the image in the AsyncPostFeed.m
Here is my code:
UIImage+Scaling.m
#implementation UIImage (Scaling)
- (UIImage *)scaleImageToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
CGFloat originX = 0.0;
CGFloat originY = 0.0;
CGRect destinationRect =
CGRectMake(originX, originY, newSize.width, newSize.height);
[self drawInRect:destinationRect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
#end
WUTPostViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *selectedImage = _imageForPost;
CGSize scaleSize = CGSizeMake(200.0f, 200.0f);
UIImage *scaleImage =
[selectedImage scaleImageToSize:scaleSize];
[self.imageViewForPost setImage:scaleImage];
...
}
WUTPostViewController.h:
#interface WUTPostViewController : WUTCommonViewController <UITextViewDelegate,UIAlertViewDelegate>
#property (strong, nonatomic) IBOutlet UILabel *lblUserName;
#property (strong, nonatomic) IBOutlet UIImageView *imageViewForPost;
#property (strong, nonatomic) IBOutlet UITextView *tvDesription;
#property (strong,nonatomic) UIImage *imageForPost;
#property (strong,nonatomic) UIImage *scaleImage;
- (void)wsPostLikeSuccessCallbackForPostId;
- (void)wsPostLikeFailCallbackWithMessage:(NSString *)errorMessage;
#end
AsyncPostFeed.m:
- (void)uploadPhoto {
WUTModelImageUploadReq *imageUploadReq = [[WUTModelImageUploadReq alloc]init];
// I'm trying to set scaleImage here
imageUploadReq.photo = [self encodeToBase64String:[UIImage imageWithData:UIImageJPEGRepresentation(self.viewControllerPost.scaleImage, 0.07f)]];
imageUploadReq.extension = #"jpg";
NSLog(#"Error: %#", imageUploadReq);
void (^wsSuccessHandler)(AFHTTPRequestOperation *operation, NSDictionary* responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(#"Pull Feed responseObject %#",responseObject);
NSError *error;
WUTModelPostImageResponse *wsResponse = [[WUTModelPostImageResponse alloc]initWithDictionary:(NSDictionary *)responseObject error:&error];
if (error) {
errorMessage = #"Failure to upload image.";
NSLog(#"Error: %#", error);
[self postExecuteFail];
}else{
if (wsResponse.success) {
WUTModelImage *imageTemp = [wsResponse.data firstObject];
[postItem setObject:imageTemp.photo forKey:#"photo"];
[self uploadPostFeed];
}else{
errorMessage = #"Failure to upload image.";
NSLog(#"Error: %#", error);
[self postExecuteFail];
}
}
};
Update
Looks like you forgot to set local variable scaleImage to scaleImage property of WUTPostViewController class.
Try this code (last line should make the trick):
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *selectedImage = _imageForPost;
CGSize scaleSize = CGSizeMake(200.0f, 200.0f);
UIImage *scaleImage =
[selectedImage scaleImageToSize:scaleSize];
[self.imageViewForPost setImage:scaleImage];
self.scaleImage = scaleImage;
...
}
Original Answer
Your resizing algorithm is correct. I use the same in my project and it perfectly works.
Looks like you send scaleImageToSize: message to nil object. That's why the result of this message is nil.
You can verify this assumption by updating code in this way:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *selectedImage = _imageForPost;
NSAssert(selectedImage != nil, #"Selected image is nil");
CGSize scaleSize = CGSizeMake(200.0f, 200.0f);
UIImage *scaleImage =
[selectedImage scaleImageToSize:scaleSize];
[self.imageViewForPost setImage:scaleImage];
...
}
As you see I added NSAssert call, so your application will crash with provided message if selected image is nil.
If NSAssert is triggered, then you need look for root cause of the problem. Basically you need verify that _imageForPost variable is initialized before viewDidLoad method is called.
Please check first image are not null
CGSize size1=CGSizeMake(300,300);
UIGraphicsBeginImageContext(size1);
[selectgalleryimage drawInRect:CGRectMake(0, 0,size1.width, size1.height)];
UIImage *SELECTED_IMG1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Getting Bad Access on defined function

I keep getting a EXC_BAD_ACCESS on certain functions in a class. If I change the name of the function the error seems to go away...but I want to know why this is happening, because I happen to like the names that I'm giving my functions.
This is my h file-
#property(strong, nonatomic)NSString* month;
#property(strong,nonatomic)NSString* day;
#property(strong,nonatomic)NSString* description;
#property(strong,nonatomic)NSString* type;
#property(strong,nonatomic)NSString* venue;
#property(weak,nonatomic)IBOutlet UIImageView* imageView;
#property(weak,nonatomic)IBOutlet UILabel* descriptionLabel;
#property(weak,nonatomic)IBOutlet UILabel* venueLabel;
#property(weak,nonatomic)IBOutlet UILabel* titleLabel;
#property(weak,nonatomic)IBOutlet UILabel* typeLabel;
#property(weak,nonatomic)IBOutlet UILabel* dateLabel;
#property(weak,nonatomic)IBOutlet UILabel* monthLabel;
#property(weak,nonatomic)IBOutlet UILabel* dayLabel;
-(void)setDate:(NSString*)month withDay:(NSString*)day;
-(void)setImage:(UIImage*)image;
These are my setters -
-(void)setDescription:(NSString *)description{
self.description = description;
self.descriptionLabel.text = description;
}
-(void)setTitle:(NSString *)title{
self.title = title;
self.titleLabel.text = title;
}
-(void)setType:(NSString *)type{
self.type = type;
self.typeLabel.text = type;
}
-(void)setVenue:(NSString *)venue{
self.venue = venue;
self.venueLabel.text = venue;
}
-(void)setDate:(NSString *)month withDay:(NSString *)day{
self.month = month;
self.day = day;
}
-(void)setImage:(UIImage*)image{
self.imageView.image = image;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
self.monthLabel.text = self.month;
self.dayLabel.text = self.day;
}
If I run this - I get a EXC_BAD_ACCESS on setTitle. If I change that to setEventTitle the error goes away, and I get a EXC_BAD_ACCESS on setVenue.
This is how I'm calling these functions-
-(UIView*)getEventResultView:(NSDictionary*)component{
EventViewController* eventVC = [[EventViewController alloc] initWithNibName:#"EventResultView" bundle:nil];
NSDictionary* dateDictionary = someDate;
NSString* month= [self findMonth:dateDictionary];
[eventVC setDate:month withDay:someDay];
[eventVC setTitle: someTitle];
[eventVC setVenue: someVenue];
[eventVC setDescription:someDescription];
NSString* titleImageUrl = someUrl;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSData *titleImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:titleImageUrl]];
UIImage* titleImage = [UIImage imageWithData:titleImageData];
[eventVC setImage: titleImage];
});
return eventVC.view;
}
Why is this happening?
You have an endless recursion:
-(void)setType:(NSString *)type
{
self.type = type;
…
}
It is here:
self.type = …;
is the short form of
[self setType:…];
So the method (there are no functions in your code) is called while it is executed.
Do this:
-(void)setType:(NSString *)type
{
_type = type;
…
}

How to write block definition using properties?

I am writing a class for getting image from Photos Library.
I want one single method that will return selected image from library.
So i started writing a class named MediaBrowser.
I used block that will give selected image. But I am confused where to write block definition. Please correct the code if i am going wrong.
In MediaBrowser.h
#interface MediaBrowser : NSObject
typedef UIImage* (^MediaBrowserCompletionHandler)(void);
+ (id)sharedInstance;
- (BOOL)startMediaBrowserFromViewController:(UIViewController*)controller
completionHandler:(MediaBrowserCompletionHandler)completion;
#end
In MediaBrowser.m
#interface MediaBrowser () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (nonatomic, strong) MediaBrowserCompletionHandler completionHandler;
#end
#implementation MediaBrowser
static MediaBrowser *sharedMediaBrowser = nil;
+ (id)sharedInstance
{
if (nil != sharedMediaBrowser) {
return sharedMediaBrowser;
}
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMediaBrowser = [[MediaBrowser alloc] init];
});
return sharedMediaBrowser;
}
- (BOOL)startMediaBrowserFromViewController:(UIViewController *)controller completionHandler:(MediaBrowserCompletionHandler)completion
{
self.completionHandler = [completion copy];
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (controller == nil))
return NO;
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Displays saved pictures from the Camera Roll album.
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
mediaUI.allowsEditing = NO;
mediaUI.delegate = self;
[controller presentModalViewController:mediaUI animated:YES];
return YES;
}
// UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *imageToUse;
// Handle a still image picked from a photo album
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {
imageToUse = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
// Do something with imageToUse
if (self.completionHandler) {
// Pass here UIImage
self.completionHandler();
}
}
[picker dismissModalViewControllerAnimated:YES];
}
#end
I figured out the answer. I wanted to send selected image from UIImagePickerController to the calling class. I was writing wrong block. See corrected code below.
In MediaBrowser.h
block declaration shoudld be :
typedef void (^MediaBrowserCompletionHandler)(UIImage *selectedImage);
And in MediaBroser.m
Calling block should be :
if (self.completionHandler) {
self.completionHandler(imageToUse);
}
typedef UIImage* (^MediaBrowserCompletionHandler)(void);
#interface MediaBrowser : NSObject
#property (nonatomic,copy) MediaBrowserCompletionHandler handler;
#end
This should be fine.
typedef UIImage* (^MediaBrowserCompletionHandler)(void);
#interface MediaBrowser : NSObject
....
#end

Loading array from folder of images - xcode

I am having some trouble loading images from a file into an array. I have used a combination of questions I have found on here, and am out of ideas.... I am new to objective-c and rusty on the rest.
My viewDidLoad simply calls my showPics method, and for testing sake I have the _imgView just show the image at position 1 in the array.
It could very well be a problem with the way I am showing the images as well. I have a ViewController and one ImageView (titled: imgView) in my Storyboard.
here is my showPics method:
-(void)showPics
{
NSArray *PhotoArray = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:#"Otter_Images"];
NSMutableArray *imgQueue = [[NSMutableArray alloc] initWithCapacity:PhotoArray.count];
for (NSString* path in PhotoArray)
{
[imgQueue addObject:[UIImage imageWithContentsOfFile:path]];
}
UIImage *currentPic = _imgView.image;
int i = -1;
if (currentPic != nil && [PhotoArray containsObject:currentPic]) {
i = [PhotoArray indexOfObject:currentPic];
}
i++;
if(i < PhotoArray.count)
_imgView.image= [PhotoArray objectAtIndex:1];
}
Here is my viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showPics];
}
Here is my ViewController.h
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *imgView;
#end
Please let me know if you need anything else and thank you in advance!
In your showPics method, other than the initial 'for-loop', all of your references to PhotoArray should instead be references to imgQueue. PhotoArray is a list of pathnames. imgQueue is the array of actual UIImage objects.
-(void)showPics {
NSArray *PhotoArray = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:#"Otter_Images"];
NSMutableArray *imgQueue = [[NSMutableArray alloc] initWithCapacity:PhotoArray.count];
for (NSString* path in PhotoArray) {
[imgQueue addObject:[UIImage imageWithContentsOfFile:path]];
}
UIImage *currentPic = _imgView.image;
int i = -1;
if (currentPic != nil && [imgQueue containsObject:currentPic]) {
i = [imgQueue indexOfObject:currentPic];
}
i++;
if(i < imgQueue.count) {
_imgView.image = [imgQueue objectAtIndex:1];
}
}

Resources