Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // cash
- //
- // Created by Apple on 8/13/2557 BE.
- // Copyright (c) 2557 Apple. All rights reserved.
- //
- #import "ViewController.h"
- #import "DetailViewController.h"
- @interface ViewController ()
- {
- NSArray *tableData;
- NSArray *jsonObject;
- NSMutableArray *cashArrays;
- NSDictionary *temp;
- NSMutableArray *displayObject;
- NSArray *searchResults;
- NSMutableDictionary *testdict;
- }
- @end
- @implementation ViewController
- @synthesize tableView;
- @synthesize dict;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- tableData = [NSArray arrayWithObjects:@"mycash",@"detail",nil];
- NSData *jsondata = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"GIANT9"]];
- jsonObject = [NSJSONSerialization JSONObjectWithData:jsondata options:NSJSONReadingMutableContainers error:nil];
- //NSString *string = [dict objectForKey:@"someKey"];
- cashArrays = [[NSMutableArray alloc] init];
- for (NSDictionary *dataDict in jsonObject) {
- NSString *detail_data = [dataDict objectForKey:@"detail"];
- NSString *receipts_data = [dataDict objectForKey:@"receipts"];
- NSString *charge_data = [dataDict objectForKey:@"charge"];
- NSString *balance_data = [dataDict objectForKey:@"balance"];
- NSLog(@" detail name is : %@",detail_data);
- NSLog(@" receipts name is : %@",receipts_data);
- NSLog(@" charge name is : %@",charge_data);
- NSLog(@" balance is : %@",balance_data);
- dict = [NSDictionary dictionaryWithObjectsAndKeys:
- detail_data,@"detail",
- receipts_data,@"receipts",
- charge_data,@"charge",
- balance_data,@"balance",
- nil];
- [cashArrays addObject:dict];
- }
- //NSLog(@"object index 0 %@",[cashArrays objectAtIndex:0]);
- //testdict = [[NSMutableDictionary alloc]init];
- //testdict = [[cashArrays objectAtIndex:0]valueForKey:@"balance"];
- //NSLog(@"testdict detail 0 is : %@",testdict);
- displayObject =[[NSMutableArray alloc] initWithArray:cashArrays];
- // Do any additional setup after loading the view, typically from a nib.
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return displayObject.count;
- }
- #pragma mark Tableview
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CelleTdentifier = @"mycash";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CelleTdentifier];
- if(cell == nil){
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CelleTdentifier];
- }
- temp = [displayObject objectAtIndex:indexPath.row];
- NSString *cellValue = [temp objectForKey:@"detail"]; //cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
- cell.textLabel.text = cellValue;
- cell.imageView.image = [UIImage imageNamed:@"pictureProfilessm2014-07-15.09_29_19-53c4f46f5c033-941406_459727600783769_62486325_n.jpg"];
- return cell;
- }
- #pragma mark uisearchbar
- - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
- {
- if([searchString length] == 0)
- {
- [displayObject removeAllObjects];
- [displayObject addObjectsFromArray:cashArrays];
- }
- else
- {
- [displayObject removeAllObjects];
- for(NSDictionary *tmpDict in cashArrays)
- {
- NSString *val = [tmpDict objectForKey:@"detail"];
- NSRange r = [val rangeOfString:searchString options:NSCaseInsensitiveSearch];
- if(r.location != NSNotFound)
- {
- [displayObject addObject:tmpDict];
- }
- }
- }
- return YES;
- }
- - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
- searchBar.text=@"";
- [searchBar setShowsCancelButton:NO animated:YES];
- [searchBar resignFirstResponder];
- }
- #pragma mark heightForRowAtIndexPath
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 71;
- }
- #pragma mark send parameter
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- if ([segue.identifier isEqualToString:@"showdetail"]) {
- NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
- temp = [displayObject objectAtIndex:indexPath.row];
- NSString *cellValue = [temp objectForKey:@"detail"];
- DetailViewController *destViewController = segue.destinationViewController;
- destViewController.detail = cellValue;
- }
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement