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

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

Draw This
($0.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-04-2009, 11:01 PM   #1 (permalink)
ybrikeeg
Registered Member
 
Join Date: Jul 2009
Posts: 143
ybrikeeg is on a distinguished road
Default UIImage from UIPicker

Hey there,
I was wondering if anyone could help me with adding a image after the UIPicker is selected. If "Hybrid Roses" is selected, display image "A". If "Floribunda" is selected, display image "B". Here is my code:
Code:
#import "iRoseViewController.h"

@implementation iRoseViewController
@synthesize picker;
@synthesize stateZips;
@synthesize states;
@synthesize zips;




- (void)viewDidLoad {
	
	NSBundle *bundle = [NSBundle mainBundle];
	NSString *plistPath = [bundle pathForResource:@"statedictionary" ofType:@"plist"];
	NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
	self.stateZips = dictionary;
	[dictionary release];
	
	NSArray *components = [self.stateZips allKeys];
	NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)];
	self.states = sorted;
	
	NSString *selectedState = [self.states objectAtIndex:0];
	NSArray *array = [stateZips objectForKey:selectedState];
	self.zips = array;
}




- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; 
}


- (void)dealloc {	
	[picker release];
	[stateZips release];
	[states release];
	[zips release];
	[super dealloc];
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	if (component == kStateComponent)
		return [self.states count];
	return [self.zips count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	if (component == kStateComponent)
		return [self.states objectAtIndex:row];
	return [self.zips objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	if (component == kStateComponent)
	{
		NSString *selectedState = [self.states objectAtIndex:row];
		NSArray *array = [stateZips objectForKey:selectedState];
		self.zips = array;
		[picker selectRow:0 inComponent:kZipComponent animated:YES];
		[picker reloadComponent:kZipComponent];
	}

}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
	if (component == 0)
		return 154;
	return 160;
}


@end
Thanks
ybrikeeg is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,020
Threads: 93,864
Posts: 401,922
Top Poster: BrianSlick (7,962)
Welcome to our newest member, wendolynlm80
Powered by vBadvanced CMPS v3.1.0

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