// // CatalotTableViewController.m // AddaShoeApp // // Created by Admin on 10/17/2557 BE. // Copyright (c) 2557 Admin. All rights reserved. // #import "CatalotTableViewController.h" #import "DetailCatalogViewController.h" @interface CatalotTableViewController () { NSMutableArray *filtered; NSMutableArray *myObject; NSDictionary *dict; NSString *prodcode; NSString *images; } @end @implementation CatalotTableViewController @synthesize tbv; @synthesize searchBar; - (void)viewDidLoad { [super viewDidLoad]; prodcode = @"Prodcode"; images = @"Images"; myObject = [[NSMutableArray alloc]init]; NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://10.32.1.151:81/sample_shoe/GetData.php"]]; id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]; //values in foreach loop for (NSDictionary *dataDict in jsonObjects) { NSString *strProdCode = [dataDict objectForKey:@"prodcode"]; NSString *strImages = [dataDict objectForKey:@"images"]; dict = [NSDictionary dictionaryWithObjectsAndKeys: strProdCode,prodcode, strImages,images, nil]; [myObject addObject:dict]; } filtered = [[NSMutableArray alloc]initWithArray:myObject]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { [filtered removeAllObjects]; //ให้ทำการลบข้อมูลทั้งหมดออกก่อน if (searchText.length == 0) { [filtered addObjectsFromArray:myObject]; } else { for (NSDictionary *tmpDict in myObject) { NSString *val = [tmpDict objectForKey:prodcode]; NSRange r = [val rangeOfString:searchText options:NSCaseInsensitiveSearch]; if (r.location != NSNotFound) { [filtered addObject:tmpDict]; } } } [tbv reloadData]; //โหลด Data ใหม่ให้เป็นปัจจุบัน } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.tbv) { return myObject.count; } else{ return filtered.count; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSDictionary *tmpDict; if (tableView == self.tbv) { tmpDict = [myObject objectAtIndex:indexPath.row]; } else { tmpDict = [filtered objectAtIndex:indexPath.row]; } NSURL *url = [NSURL URLWithString:[tmpDict objectForKey:images]]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *img = [[UIImage alloc]initWithData:data]; cell.imageView.image = img; cell.textLabel.text = [tmpDict objectForKey:prodcode]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [searchBar resignFirstResponder]; } - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"mnuSelect"]) { NSIndexPath *indexPath = [self.tbv indexPathForSelectedRow]; NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row]; [[segue destinationViewController] setImageItem:[tmpDict objectForKey:images]]; [[segue destinationViewController] setModelItem:[tmpDict objectForKey:prodcode]]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง