Last active
August 29, 2015 14:05
-
-
Save FabiolaRamirez/5811534c2e59e49ca7bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "PlacesCategoryTableViewController.h" | |
#import "PlacesTableViewController.h" | |
@interface PlacesCategoryTableViewController (){ | |
NSArray * categorias; | |
NSArray *searchResults; | |
} | |
@end | |
@implementation PlacesCategoryTableViewController | |
- (id)initWithStyle:(UITableViewStyle)style | |
{ | |
self = [super initWithStyle:style]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
//Query | |
categorias = [[NSMutableArray alloc] init]; | |
PFQuery *query = [PFQuery queryWithClassName:@"Categoria"]; | |
//[query orderByAscending:@"Tipo"]; | |
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { | |
if (!error) { | |
// The find succeeded. | |
NSLog(@"Successfully retrieved %i scores.", (int)objects.count); | |
categorias = objects; | |
//actualizar tabla con datos | |
[self.tableView reloadData]; | |
} else { | |
// Log details of the failure | |
NSLog(@"Error: %@ %@", error, [error userInfo]); | |
} | |
}]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
//metodo manejo filtro de busqueda | |
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope | |
{ | |
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText]; | |
searchResults = [categorias filteredArrayUsingPredicate:resultPredicate]; | |
} | |
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString | |
{ | |
[self filterContentForSearchText:searchString | |
scope:[[self.searchDisplayController.searchBar scopeButtonTitles] | |
objectAtIndex:[self.searchDisplayController.searchBar | |
selectedScopeButtonIndex]]]; | |
return YES; | |
} | |
//*** | |
#pragma mark - Table view data source | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
//search | |
if (tableView == self.searchDisplayController.searchResultsTableView) { | |
return [searchResults count]; | |
} else { | |
return [categorias count]; | |
} | |
//** | |
//return [categorias count]; | |
} | |
// sirve para decir que mostrar en la celda indexPath | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"categoriaCell" forIndexPath:indexPath]; | |
// Configure the cell... | |
UILabel * nombreLabel = (UILabel *)[cell viewWithTag:2]; | |
UIImageView * fotoImageView = (UIImageView *)[cell viewWithTag:1]; | |
//PFObject *categoria = [categorias objectAtIndex:indexPath.row]; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"categoriaCell"]; | |
} | |
//search | |
PFObject *categoria=nil; | |
if (tableView == self.searchDisplayController.searchResultsTableView) { | |
categoria = [searchResults objectAtIndex:indexPath.row]; | |
} else { | |
categoria = [categorias objectAtIndex:indexPath.row]; | |
} | |
//*** | |
nombreLabel.text = categoria[@"name"]; | |
[fotoImageView setImageWithURL:[NSURL URLWithString:categoria[@"urlImage"]] | |
placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; | |
return cell; | |
} | |
// darle accion a la celda indexPath | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSLog(@"SE PRESIONO %i", (int)indexPath.row); | |
PFObject *categoria = [categorias objectAtIndex:indexPath.row]; | |
// push para continuar | |
PlacesTableViewController *tableViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"placesTableViewController"]; | |
tableViewController.qwe = categoria; | |
[self.navigationController pushViewController:tableViewController animated:YES]; | |
// modal es para salir de contexto | |
/*UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"placeViewController"]; | |
[self presentViewController:viewController animated:YES completion:nil]; | |
*/ | |
} | |
/* | |
// Override to support conditional editing of the table view. | |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
// Return NO if you do not want the specified item to be editable. | |
return YES; | |
} | |
*/ | |
/* | |
// Override to support editing the table view. | |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
if (editingStyle == UITableViewCellEditingStyleDelete) { | |
// Delete the row from the data source | |
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
} else if (editingStyle == UITableViewCellEditingStyleInsert) { | |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view | |
} | |
} | |
*/ | |
/* | |
// Override to support rearranging the table view. | |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath | |
{ | |
} | |
*/ | |
/* | |
// Override to support conditional rearranging of the table view. | |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
// Return NO if you do not want the item to be re-orderable. | |
return YES; | |
} | |
*/ | |
#pragma mark - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
//search | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender | |
{ | |
// Get the new view controller using [segue destinationViewController]. | |
// Pass the selected object to the new view controller. | |
PFObject *categoria = nil; | |
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) { | |
NSIndexPath *indexPath = nil; | |
if (self.searchDisplayController.active) { | |
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; | |
categoria = [searchResults objectAtIndex:indexPath.row]; | |
} else { | |
indexPath = [self.tableView indexPathForSelectedRow]; | |
categoria = [categorias objectAtIndex:indexPath.row]; | |
} | |
} | |
PlacesTableViewController *destViewController = segue.destinationViewController; | |
destViewController.qwe = categoria; | |
} | |
//****** | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Deje un comentario