Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // PickerViewViewController.m
- // PickerView
- //
- // Created by Diogo Techera on 3/16/11.
- // Copyright 2011 __MyCompanyName__. All rights reserved.
- //
- #import "PickerViewViewController.h"
- @implementation PickerViewViewController
- - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
- {
- if (component == 0)
- {
- return [[continente objectAtIndex:row]objectForKey:@"nome"];
- }
- else if (component ==1){
- NSMutableDictionary *d = [continente objectAtIndex:selectedContinent];
- NSMutableArray *paises = [d objectForKey:@"paises"];
- return [[paises objectAtIndex:row] objectForKey:@"nome"];
- }
- return nil;
- }
- - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
- {
- return 2;
- }
- - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- {
- if(component == 0)
- {
- return [continente count];
- }
- else if (component ==1)
- {
- NSMutableDictionary *d = [continente objectAtIndex:selectedContinent];
- NSMutableArray *paises = [d objectForKey:@"paises"];
- return [paises count];
- }
- return 0;
- }
- - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
- {
- if (component == 0) {
- selectedContinent = row;
- [pickerView reloadComponent:1];
- [pickerView selectRow:0 inComponent:1 animated:YES];
- NSMutableDictionary *dadosContinente = [continente objectAtIndex:selectedContinent];
- NSMutableArray *paisesDoContinente = [dadosContinente objectForKey:@"paises"];
- NSMutableDictionary *dadosPais = [paisesDoContinente objectAtIndex:0];
- NSString *nomeDaImagem = [dadosPais objectForKey:@"imagem"];
- UIImage *image =[UIImage imageNamed:nomeDaImagem];
- imageView.image = image;
- } else if (component == 1) {
- NSMutableDictionary *dadosContinente = [continente objectAtIndex:selectedContinent];
- NSMutableArray *paisesDoContinente = [dadosContinente objectForKey:@"paises"];
- NSMutableDictionary *dadosPais = [paisesDoContinente objectAtIndex:row];
- NSString *nomeDaImagem = [dadosPais objectForKey:@"imagem"];
- UIImage *image =[UIImage imageNamed:nomeDaImagem];
- imageView.image = image;
- }
- }
- /*
- // The designated initializer. Override to perform setup that is required before the view is loaded.
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- */
- /*
- // Implement loadView to create a view hierarchy programmatically, without using a nib.
- - (void)loadView {
- }
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- continente =[[NSMutableArray alloc]init];
- NSMutableDictionary *cont =[[[NSMutableDictionary alloc]init] autorelease];
- NSMutableArray *paises =[[[NSMutableArray alloc]init] autorelease];
- NSMutableDictionary *pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Cameroon" forKey:@"nome"];
- [pais setObject:@"Cameroon.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Saudi Arabia" forKey:@"nome"];
- [pais setObject:@"Saudi Arabia.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"South Africa" forKey:@"nome"];
- [pais setObject:@"South Africa.gif" forKey:@"imagem"];
- [paises addObject:pais];
- [cont setObject:paises forKey:@"paises"];
- [cont setObject:@"Africa" forKey:@"nome"];
- [continente addObject:cont];
- cont =[[[NSMutableDictionary alloc]init] autorelease];
- paises =[[[NSMutableArray alloc]init] autorelease];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Brazil" forKey:@"nome"];
- [pais setObject:@"Brazil.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Uruguay" forKey:@"nome"];
- [pais setObject:@"Uruguay.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Argentina" forKey:@"nome"];
- [pais setObject:@"Argentina.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"USA" forKey:@"nome"];
- [pais setObject:@"USA.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Canada" forKey:@"nome"];
- [pais setObject:@"Canada.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Mexico" forKey:@"nome"];
- [pais setObject:@"Mexico.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Chile" forKey:@"nome"];
- [pais setObject:@"Chile.gif" forKey:@"imagem"];
- [paises addObject:pais];
- [cont setObject:paises forKey:@"paises"];
- [cont setObject:@"America" forKey:@"nome"];
- [continente addObject:cont];
- cont =[[[NSMutableDictionary alloc]init] autorelease];
- paises =[[[NSMutableArray alloc]init] autorelease];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"UK" forKey:@"nome"];
- [pais setObject:@"UK.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"France" forKey:@"nome"];
- [pais setObject:@"France.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Ireland" forKey:@"nome"];
- [pais setObject:@"Ireland.gif" forKey:@"imagem"];
- [paises addObject:pais];
- pais =[[[NSMutableDictionary alloc]init] autorelease];
- [pais setObject:@"Italy" forKey:@"nome"];
- [pais setObject:@"Italy.gif" forKey:@"imagem"];
- [paises addObject:pais];
- [cont setObject:paises forKey:@"paises"];
- [cont setObject:@"Europa" forKey:@"nome"];
- [continente addObject:cont];
- }
- /*
- // Override to allow orientations other than the default portrait orientation.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- */
- - (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- - (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (void)dealloc {
- [super dealloc];
- }
- @end
Add Comment
Please, Sign In to add comment