1

I'm trying to code an app in Xcode 4, with storyboarding.

My project is something like this:

1 table view controller

1 detail view controller with 4 buttons,

and say 6 images( 1-1.jpg/1-2.jpg/1-3.jpg, and 2-1.jpg/2-2.jpg/2-3.jpg.

I have got my app to show the images(1-1.jpg and 2-1.jpg) in the array when clicking the cells.

My Screenshots And this is my code:

// TableViewController.m:

@synthesize myTitle = _myTitle; @synthesize myScene = _myScene; @synthesize myImages = _myImages; - (void)viewDidLoad { [super viewDidLoad]; self.myTitle = [[NSArray alloc] initWithObjects:@"Chicken", @"Flower", nil]; self.myScene = [[NSArray alloc] initWithObjects:@"1", @"2", nil]; self.myImages = [[NSArray alloc] initWithObjects:@"1-1.jpg", @"2-1.jpg", nil]; } 

// DetailViewController.m

@synthesize titleLabel = _titleLabel; @synthesize sceneLabel = _sceneLabel; @synthesize imageView = _imageView; @synthesize myDetailModel = _myDetailModel; - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = self.titleLabel.text = [self.myDetailModel objectAtIndex:0]; self.sceneLabel.text = [self.myDetailModel objectAtIndex:1]; self.imageView.image = [UIImage imageNamed: [self.myDetailModel objectAtIndex:2]]; 

I want my DetailView page to show the next or previous image(1-2.jpg/1-3.jpg... / 2-2.jpg, 2-3.jpg...) each time I press next or previous (black)button,

and to show next or previous scene(chicken scene and flower scene) when I press another (green)buttons,
like https://dl.dropboxusercontent.com/u/7493131/q3.jpg

I don't know how to array 1-2.jpg, 1-3.jpg, 2-2.jpg and 2-3.jpg and what to do with them.

I am so new that I would like some example code to help please to study how it works, and how I can implement similar within my app. Thank you.

2 Answers 2

1
-(IBAction)rightClick{ if (imageArrayObj.count > 0) { currentIndex++; if (currentIndex > imageArrayObj.count - 1) { currentIndex = 0; } imageViewObj.image = [imageArrayObj objectAtIndex:currentIndex]; } } 

It's working properly ..... Use this and currentIndex is integer declare " int currentIndex;" and assign value in view did load "currentIndex = 0;"

Sign up to request clarification or add additional context in comments.

3 Comments

Dosen't seem to work.. when I press rightClick button, nothing happens. I'm still trying what went wrong. If you have the time, could you please let me know how to show flower action and fighter action? Thank you for your help!
Sorry I put the wrong image file names (- instead of _) and that was why. It works after I changed file names but not in order.. I'm trying to figure out a way to do it. Thank you!
I removed "currentindex=0" and used this code and now it works. (IBAction)rightClick:(id)sender { if (currentImage +1 < [imageArrayObj count]) { currentImage++; UIImage *img = [imageArrayObj objectAtIndex:currentImage]; _imageView.image = img; } Thank you!
1

You need to create an instance int variable idx to keep track of which image you are handling and assign two IBActions to those buttons :

// This is for your fighter case - (IBAction)presentPreviousImage:(id)sender { idx --; if (idx == 2) { self.imageView.image = [UIImage imageNamed:@"1-3.jpg"]; } else if (idx == 1) { self.imageView.image = [UIImage imageNamed:@"1-2.jpg"]; } else if (idx == 0) { self.imageView.image = [UIImage imageNamed:@"1-1.jpg"]; idx = 2; } } - (IBAction)presentNextImage:(id)sender { idx ++; if (idx == 0) { self.imageView.image = [UIImage imageNamed:@"1-2.jpg"]; } else if (idx == 1) { self.imageView.image = [UIImage imageNamed:@"1-3.jpg"]; } else if (idx == 2) { self.imageView.image = [UIImage imageNamed:@"1-1.jpg"]; idx = 0; } } 

4 Comments

Hi, thank you for the code. It works perfectly for my fighter case. Now would you please let me know what to do with my flower case? Because when I press presentNextImage/presentPreviousImage button in flower detail page, only the fighter appears.
I am glad it works for you. For the flower, you can ask the controller title, or make another index. If you still have problems, let me know and I will try to give a more detailed answer
Oh, I have no idea what to do with controller title or index thing.. Would you please give more details? plus, what if I have about 70 images for fighter case? Do I have to input all the file names? Thank you very much!
give me your email and I can help you with it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.