Guest User

Untitled

a guest
Jan 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. //
  2. // PickerViewViewController.m
  3. // PickerView
  4. //
  5. // Created by Diogo Techera on 3/16/11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "PickerViewViewController.h"
  10.  
  11. @implementation PickerViewViewController
  12.  
  13.  
  14. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  15. {
  16. if (component == 0)
  17. {
  18. return [[continente objectAtIndex:row]objectForKey:@"nome"];
  19. }
  20. else if (component ==1){
  21. NSMutableDictionary *d = [continente objectAtIndex:selectedContinent];
  22. NSMutableArray *paises = [d objectForKey:@"paises"];
  23.  
  24. return [[paises objectAtIndex:row] objectForKey:@"nome"];
  25.  
  26. }
  27. return nil;
  28.  
  29. }
  30.  
  31.  
  32. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  33. {
  34. return 2;
  35. }
  36.  
  37. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  38. {
  39.  
  40. if(component == 0)
  41. {
  42. return [continente count];
  43. }
  44. else if (component ==1)
  45. {
  46. NSMutableDictionary *d = [continente objectAtIndex:selectedContinent];
  47. NSMutableArray *paises = [d objectForKey:@"paises"];
  48.  
  49. return [paises count];
  50. }
  51. return 0;
  52. }
  53.  
  54. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
  55. {
  56. if (component == 0) {
  57. selectedContinent = row;
  58.  
  59. [pickerView reloadComponent:1];
  60. [pickerView selectRow:0 inComponent:1 animated:YES];
  61.  
  62. NSMutableDictionary *dadosContinente = [continente objectAtIndex:selectedContinent];
  63.  
  64. NSMutableArray *paisesDoContinente = [dadosContinente objectForKey:@"paises"];
  65. NSMutableDictionary *dadosPais = [paisesDoContinente objectAtIndex:0];
  66. NSString *nomeDaImagem = [dadosPais objectForKey:@"imagem"];
  67. UIImage *image =[UIImage imageNamed:nomeDaImagem];
  68. imageView.image = image;
  69. } else if (component == 1) {
  70.  
  71. NSMutableDictionary *dadosContinente = [continente objectAtIndex:selectedContinent];
  72.  
  73. NSMutableArray *paisesDoContinente = [dadosContinente objectForKey:@"paises"];
  74. NSMutableDictionary *dadosPais = [paisesDoContinente objectAtIndex:row];
  75. NSString *nomeDaImagem = [dadosPais objectForKey:@"imagem"];
  76. UIImage *image =[UIImage imageNamed:nomeDaImagem];
  77. imageView.image = image;
  78. }
  79.  
  80. }
  81.  
  82.  
  83. /*
  84. // The designated initializer. Override to perform setup that is required before the view is loaded.
  85. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  86. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  87. if (self) {
  88. // Custom initialization
  89. }
  90. return self;
  91. }
  92. */
  93.  
  94. /*
  95. // Implement loadView to create a view hierarchy programmatically, without using a nib.
  96. - (void)loadView {
  97. }
  98. */
  99.  
  100.  
  101. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  102. - (void)viewDidLoad
  103. {
  104.  
  105. [super viewDidLoad];
  106. continente =[[NSMutableArray alloc]init];
  107.  
  108. NSMutableDictionary *cont =[[[NSMutableDictionary alloc]init] autorelease];
  109. NSMutableArray *paises =[[[NSMutableArray alloc]init] autorelease];
  110.  
  111. NSMutableDictionary *pais =[[[NSMutableDictionary alloc]init] autorelease];
  112. [pais setObject:@"Cameroon" forKey:@"nome"];
  113. [pais setObject:@"Cameroon.gif" forKey:@"imagem"];
  114. [paises addObject:pais];
  115.  
  116. pais =[[[NSMutableDictionary alloc]init] autorelease];
  117. [pais setObject:@"Saudi Arabia" forKey:@"nome"];
  118. [pais setObject:@"Saudi Arabia.gif" forKey:@"imagem"];
  119. [paises addObject:pais];
  120.  
  121. pais =[[[NSMutableDictionary alloc]init] autorelease];
  122. [pais setObject:@"South Africa" forKey:@"nome"];
  123. [pais setObject:@"South Africa.gif" forKey:@"imagem"];
  124. [paises addObject:pais];
  125.  
  126. [cont setObject:paises forKey:@"paises"];
  127. [cont setObject:@"Africa" forKey:@"nome"];
  128.  
  129. [continente addObject:cont];
  130.  
  131.  
  132. cont =[[[NSMutableDictionary alloc]init] autorelease];
  133. paises =[[[NSMutableArray alloc]init] autorelease];
  134.  
  135. pais =[[[NSMutableDictionary alloc]init] autorelease];
  136. [pais setObject:@"Brazil" forKey:@"nome"];
  137. [pais setObject:@"Brazil.gif" forKey:@"imagem"];
  138. [paises addObject:pais];
  139.  
  140. pais =[[[NSMutableDictionary alloc]init] autorelease];
  141. [pais setObject:@"Uruguay" forKey:@"nome"];
  142. [pais setObject:@"Uruguay.gif" forKey:@"imagem"];
  143. [paises addObject:pais];
  144.  
  145. pais =[[[NSMutableDictionary alloc]init] autorelease];
  146. [pais setObject:@"Argentina" forKey:@"nome"];
  147. [pais setObject:@"Argentina.gif" forKey:@"imagem"];
  148. [paises addObject:pais];
  149.  
  150. pais =[[[NSMutableDictionary alloc]init] autorelease];
  151. [pais setObject:@"USA" forKey:@"nome"];
  152. [pais setObject:@"USA.gif" forKey:@"imagem"];
  153. [paises addObject:pais];
  154.  
  155. pais =[[[NSMutableDictionary alloc]init] autorelease];
  156. [pais setObject:@"Canada" forKey:@"nome"];
  157. [pais setObject:@"Canada.gif" forKey:@"imagem"];
  158. [paises addObject:pais];
  159.  
  160. pais =[[[NSMutableDictionary alloc]init] autorelease];
  161. [pais setObject:@"Mexico" forKey:@"nome"];
  162. [pais setObject:@"Mexico.gif" forKey:@"imagem"];
  163. [paises addObject:pais];
  164.  
  165. pais =[[[NSMutableDictionary alloc]init] autorelease];
  166. [pais setObject:@"Chile" forKey:@"nome"];
  167. [pais setObject:@"Chile.gif" forKey:@"imagem"];
  168. [paises addObject:pais];
  169.  
  170. [cont setObject:paises forKey:@"paises"];
  171. [cont setObject:@"America" forKey:@"nome"];
  172. [continente addObject:cont];
  173.  
  174.  
  175. cont =[[[NSMutableDictionary alloc]init] autorelease];
  176. paises =[[[NSMutableArray alloc]init] autorelease];
  177.  
  178. pais =[[[NSMutableDictionary alloc]init] autorelease];
  179. [pais setObject:@"UK" forKey:@"nome"];
  180. [pais setObject:@"UK.gif" forKey:@"imagem"];
  181. [paises addObject:pais];
  182.  
  183. pais =[[[NSMutableDictionary alloc]init] autorelease];
  184. [pais setObject:@"France" forKey:@"nome"];
  185. [pais setObject:@"France.gif" forKey:@"imagem"];
  186. [paises addObject:pais];
  187.  
  188. pais =[[[NSMutableDictionary alloc]init] autorelease];
  189. [pais setObject:@"Ireland" forKey:@"nome"];
  190. [pais setObject:@"Ireland.gif" forKey:@"imagem"];
  191. [paises addObject:pais];
  192.  
  193. pais =[[[NSMutableDictionary alloc]init] autorelease];
  194. [pais setObject:@"Italy" forKey:@"nome"];
  195. [pais setObject:@"Italy.gif" forKey:@"imagem"];
  196. [paises addObject:pais];
  197.  
  198. [cont setObject:paises forKey:@"paises"];
  199. [cont setObject:@"Europa" forKey:@"nome"];
  200.  
  201.  
  202. [continente addObject:cont];
  203.  
  204.  
  205. }
  206.  
  207.  
  208. /*
  209. // Override to allow orientations other than the default portrait orientation.
  210. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  211. // Return YES for supported orientations
  212. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  213. }
  214. */
  215.  
  216. - (void)didReceiveMemoryWarning {
  217. // Releases the view if it doesn't have a superview.
  218. [super didReceiveMemoryWarning];
  219.  
  220. // Release any cached data, images, etc that aren't in use.
  221. }
  222.  
  223. - (void)viewDidUnload {
  224. // Release any retained subviews of the main view.
  225. // e.g. self.myOutlet = nil;
  226. }
  227.  
  228.  
  229. - (void)dealloc {
  230. [super dealloc];
  231. }
  232.  
  233. @end
Add Comment
Please, Sign In to add comment