Advertisement
Guest User

Untitled

a guest
Jul 19th, 2015
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  AsaSulViewController.m
  3. //  MinhaBrasilia
  4. //
  5. //  Created by Filipe Manuel on 7/17/15.
  6. //  Copyright (c) 2015 Filipe Manuel. All rights reserved.
  7. //
  8.  
  9. #import "CategoriaAsaSulViewController.h"
  10. #import "Categoria.h"
  11. #import "Loja.h"
  12. #import "EstabelecimentoViewController.h"
  13. #import "CelulaEstabelecimentoTableViewCell.h"
  14. #import <MagicalRecord/MagicalRecord.h>
  15. #import <MagicalRecord/MagicalRecord+ShorthandMethods.h>
  16. #import <MagicalRecord/MagicalRecordShorthandMethodAliases.h>
  17.  
  18.  
  19. @interface CategoriaAsaSulViewController () <UITableViewDataSource, UITableViewDelegate>
  20.  
  21. @property (nonatomic, retain) Categoria *categoria;
  22. @property (nonatomic, retain) Loja *loja;
  23. @property (weak, nonatomic) IBOutlet UITableView *tableViewCategorias;
  24. @property (nonatomic, strong) NSMutableArray *listaCategorias;
  25.  
  26. @end
  27.  
  28. @implementation CategoriaAsaSulViewController
  29. @synthesize categoria;
  30. @synthesize listaCategorias;
  31. @synthesize tableViewCategorias;
  32.  
  33. NSString *const IdentificadorCelula = @"idCelulaCategoria";
  34. NSString *const IdentificadorSegue = @"segueTabelaCategoria";
  35.  
  36. // Do any additional setup after loading the view.
  37. - (void)viewDidLoad {
  38.     [super viewDidLoad];
  39.    
  40.     [self.tableViewCategorias setDelegate:self];
  41.     [self.tableViewCategorias setDataSource:self];
  42. }
  43.  
  44. // Dispose of any resources that can be recreated.
  45. - (void)didReceiveMemoryWarning {
  46.     [super didReceiveMemoryWarning];
  47.    
  48. }
  49.  
  50. - (void) viewWillAppear:(BOOL)animated {
  51.     [super viewWillAppear:animated];
  52.     [self carregarCategoriasAsaSul];
  53. }
  54.  
  55. #pragma mark - Carregar categorias
  56. - (void) carregarCategoriasAsaSul {
  57.     self.categoria = [Categoria MR_createEntity];
  58.     self.listaCategorias = [[NSMutableArray alloc] init];
  59.    
  60.     NSString *caminho = [[NSBundle mainBundle] pathForResource:@"CategoriaAsaSul" ofType:@"plist"];
  61.     NSDictionary *minhaPList = [NSDictionary dictionaryWithContentsOfFile:caminho];
  62.    
  63.     self.listaCategorias = [minhaPList objectForKey:@"categorias"];
  64. }
  65.  
  66.  
  67. #pragma mark - Açáes da tabela
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  69.     return self.listaCategorias.count;
  70. }
  71.  
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  73.     UITableViewCell *celula = [tableView dequeueReusableCellWithIdentifier:IdentificadorCelula
  74.                                                               forIndexPath:indexPath];
  75.    
  76.     if(!celula){
  77.         celula = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
  78.                                         reuseIdentifier:IdentificadorCelula];
  79.     }
  80.    
  81.     [celula setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  82.    
  83.     NSString *texto = [self.listaCategorias objectAtIndex:indexPath.row];
  84.     [celula.textLabel setText:texto];
  85.  
  86.     return celula;
  87. }
  88.  
  89. - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  90.     NSString *categoriaClicada = [self.listaCategorias objectAtIndex:indexPath.row];
  91.     [self performSegueWithIdentifier:IdentificadorSegue sender:categoriaClicada];
  92. }
  93.  
  94. #pragma mark - Segue
  95. //not working
  96. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  97.     if([segue.identifier isEqualToString:IdentificadorSegue]) {
  98.         UINavigationController *navigationController = [segue destinationViewController];
  99.         EstabelecimentoViewController *destino = (EstabelecimentoViewController *)([navigationController viewControllers][0]);
  100.         [destino setFCategoria:sender];
  101.     }
  102. }
  103.  
  104. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement