Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AsaSulViewController.m
- // MinhaBrasilia
- //
- // Created by Filipe Manuel on 7/17/15.
- // Copyright (c) 2015 Filipe Manuel. All rights reserved.
- //
- #import "CategoriaAsaSulViewController.h"
- #import "Categoria.h"
- #import "Loja.h"
- #import "EstabelecimentoViewController.h"
- #import "CelulaEstabelecimentoTableViewCell.h"
- #import <MagicalRecord/MagicalRecord.h>
- #import <MagicalRecord/MagicalRecord+ShorthandMethods.h>
- #import <MagicalRecord/MagicalRecordShorthandMethodAliases.h>
- @interface CategoriaAsaSulViewController () <UITableViewDataSource, UITableViewDelegate>
- @property (nonatomic, retain) Categoria *categoria;
- @property (nonatomic, retain) Loja *loja;
- @property (weak, nonatomic) IBOutlet UITableView *tableViewCategorias;
- @property (nonatomic, strong) NSMutableArray *listaCategorias;
- @end
- @implementation CategoriaAsaSulViewController
- @synthesize categoria;
- @synthesize listaCategorias;
- @synthesize tableViewCategorias;
- NSString *const IdentificadorCelula = @"idCelulaCategoria";
- NSString *const IdentificadorSegue = @"segueTabelaCategoria";
- // Do any additional setup after loading the view.
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.tableViewCategorias setDelegate:self];
- [self.tableViewCategorias setDataSource:self];
- }
- // Dispose of any resources that can be recreated.
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void) viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self carregarCategoriasAsaSul];
- }
- #pragma mark - Carregar categorias
- - (void) carregarCategoriasAsaSul {
- self.categoria = [Categoria MR_createEntity];
- self.listaCategorias = [[NSMutableArray alloc] init];
- NSString *caminho = [[NSBundle mainBundle] pathForResource:@"CategoriaAsaSul" ofType:@"plist"];
- NSDictionary *minhaPList = [NSDictionary dictionaryWithContentsOfFile:caminho];
- self.listaCategorias = [minhaPList objectForKey:@"categorias"];
- }
- #pragma mark - Açáes da tabela
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.listaCategorias.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *celula = [tableView dequeueReusableCellWithIdentifier:IdentificadorCelula
- forIndexPath:indexPath];
- if(!celula){
- celula = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
- reuseIdentifier:IdentificadorCelula];
- }
- [celula setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
- NSString *texto = [self.listaCategorias objectAtIndex:indexPath.row];
- [celula.textLabel setText:texto];
- return celula;
- }
- - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- NSString *categoriaClicada = [self.listaCategorias objectAtIndex:indexPath.row];
- [self performSegueWithIdentifier:IdentificadorSegue sender:categoriaClicada];
- }
- #pragma mark - Segue
- //not working
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- if([segue.identifier isEqualToString:IdentificadorSegue]) {
- UINavigationController *navigationController = [segue destinationViewController];
- EstabelecimentoViewController *destino = (EstabelecimentoViewController *)([navigationController viewControllers][0]);
- [destino setFCategoria:sender];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement