Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-11-2009, 02:32 PM   #8 (permalink)
trilithium
Registered Member
 
Join Date: Nov 2009
Posts: 7
trilithium is on a distinguished road
Default

Further to this post, I have just realised the following:

It turns out that using the array method does work, however I observe the following behaviour: -

I click on a button which should diplay a new view with a larger version of the image on the button - When I run the simulator, the first button press always results in an image not being displayed in the new view - However if I go back and click on the same button (or indeed another button) for all subsequent clicks, the correct image is displayed.

Only the first button press fails (and i have tried different buttons, but same result).

So for whatever reason, it takes two attempts before the imageView.image is assigned:

Code:
self.selectSlideView.imageView.image = [imageArray objectAtIndex:tmpInt];

Quote:
Originally Posted by trilithium View Post
Hi all, I have a problem with arrays and passing images between views that I would like some help on! So the background is that I have:

• RootViewController (which handles my table view)

• CommunicationViewController which handles the detail of the selected element from the table

• SelectSlideViewController which displays an image clicked on from the CommunicationViewController and allows the user to select a different one from the camera roll

So the problem:

• In the CommunicationViewConroller, I have the following code if the user clicks on a button:


Code:
- (IBAction) selectSlide:(id) sender
{
	if(self.selectSlideView == nil)
	{
	SelectSlideViewController *viewController = [[SelectSlideViewController alloc]
											initWithNibName:@"SelectSlideViewController" bundle:[NSBundle mainBundle]];
		self.selectSlideView = viewController;
		[viewController release];
	}
	
	[self.navigationController pushViewController:self.selectSlideView animated:YES];
	self.selectSlideView.cmn = cmn;
	self.selectSlideView.title = cmn.name;
	self.selectSlideView.imageView.image = self.myImage5;
}
And the above code works, if for, example, I click on button 5, as it sets image5 to the view in the “SelectSlideViewController”.

However, I would like to have multiple buttons using the same “selectSlide” action – and to do that, I need to figure out which button was pressed, and then assign the correct image to the “SelectSlideViewController” from an array of images (or a series of if-else statements which is clunky).

• So my revised code is as follows, but it doesn’t work with the array – any thoughts?:

Code:
- (IBAction) selectSlide:(id) sender
{
	if(self.selectSlideView == nil)
	{
	SelectSlideViewController *viewController = [[SelectSlideViewController alloc]
												 initWithNibName:@"SelectSlideViewController" bundle:[NSBundle mainBundle]];
		self.selectSlideView = viewController;
		[viewController release];
	}
	
	NSUInteger tmpInt = -1;
	tmpInt = [buttonArray indexOfObject:sender];
	
	[self.navigationController pushViewController:self.selectSlideView animated:YES];
	self.selectSlideView.cmn = cmn;
	self.selectSlideView.title = cmn.name;
	
	NSLog(@"The int was %d",tmpInt);
	NSLog(@"This is the image array size %d ",[imageArray count]);	
	
	If(tmpInt >-1 && tmpInt <9)
	{
		self.selectSlideView.imageView.image = [imageArray objectAtIndex:tmpInt];
	}
	/** this code works, but is a bit clunky:
	if(tmpInt == 0)
		self.selectSlideView.imageView.image = self.myImage1;
	else if (tmpInt == 1)
		self.selectSlideView.imageView.image = self.myImage2;
	else if (tmpInt == 2)
		self.selectSlideView.imageView.image = self.myImage3;
	else if (tmpInt == 3)
		self.selectSlideView.imageView.image = self.myImage4;
	else if (tmpInt == 4)
		self.selectSlideView.imageView.image = self.myImage5;
	else if (tmpInt == 5)
		self.selectSlideView.imageView.image = self.myImage6;
	else if (tmpInt == 6)
		self.selectSlideView.imageView.image = self.myImage7;
	else if (tmpInt == 7)
		self.selectSlideView.imageView.image = self.myImage8;
	else if (tmpInt == 8)
		self.selectSlideView.imageView.image = self.myImage9;	
	**/
}
trilithium is offline   Reply With Quote
 

» Advertisements
» Online Users: 581
22 members and 559 guests
.Snipe, cclark, cdbeshore, chrisfromnz, djbrooks111, djohnson, Domele, gordo26, iGamesDev, jon01, mediaspree, minglei, ndhieuvn212, nguyenhieu129, Rudy, SuperDietGenius, Techgirl-52, tjfallon, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,319
Threads: 93,989
Posts: 402,413
Top Poster: BrianSlick (7,978)
Welcome to our newest member, st02197
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.