Новичок
Профиль
Группа: Участник
Сообщений: 4
Регистрация: 12.5.2014
Репутация: нет Всего: нет
|
Код | #import "ResultAutoTableViewController.h" #import "User.h" #import "WebAPI.h" #import "AutoTableViewCell.h" #import "KartkaViewController.h" #import "Localisator.h" #import "SVPullToRefresh.h" #import "GiFHUD.h"
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) NSArray *year; NSArray *kilod; NSArray *sos; NSArray *prob; NSArray *about; NSArray *teh; NSArray *priced; NSArray *pricee; NSArray *priceg; NSArray *model; NSArray *date; NSArray *name; NSArray *nomer; NSArray *nomer2; NSArray *fdate; NSArray *avtocount; NSArray *photos; NSArray *bigphotos; NSArray *marka; NSArray *iduser; NSArray *kyzov; NSArray *citys; NSArray *kpp; NSArray *pal; NSArray *objem; NSArray *power; NSArray *peredac; NSArray *formula; NSArray *color; NSArray *gruzpod; NSArray *allpage; NSArray *allavto; NSString *myKyzov; NSString *totalpages; NSString *totalavto; NSString *myCities; NSString *myKPP; NSString *myToplivo; NSString *myColor; NSString *mySos; NSString *myTeh; UIImage *imim; NSArray *responsePhotos; NSString *filePath; NSData*dataimage; NSArray *id_auto; int Pages = 1;
@interface ResultAutoTableViewController () @property (nonatomic, strong) NSMutableArray *dataSource; @end
@implementation ResultAutoTableViewController
- (void)viewDidLoad { [super viewDidLoad]; [GiFHUD showWithOverlay]; _lrezalt.hidden=YES; _counter.hidden=YES; [GiFHUD setGifWithImageName:@"load2.gif"];
[self performSelector:@selector(myind) withObject:nil afterDelay:[self.counter.text isEqualToString:@"0"]];
[self configureViewFromLocalisation]; }
-(void)myind{ _lrezalt.hidden=NO; _counter.hidden=NO; [GiFHUD dismiss]; [self.rezaltAutoTableView reloadData]; }
-(void)configureViewFromLocalisation { [self.lrezalt setText:LOCALIZATION(@"Search results")]; }
+(User*)WebApiAuto:(NSString *)model_avto count_avto:(NSString *)count_avto photo_plus:(NSString *)photo_plus category_avto:(NSString *)category_avto year_avto1:(NSString *)year_avto1 year_avto2:(NSString *)year_avto2 kyzov_avto:(NSString *)kyzov_avto marka_avto:(NSString *)marka_avto region_avto:(NSString *)region_avto city_avto:(NSString *)city_avto price_from:(NSString *)price_from price_to:(NSString *)price_to valuta_avto:(NSString *)valuta_avto milage_from:(NSString *)milage_from milage_to:(NSString *)milage_to toplivo:(NSString *)toplivo korobka:(NSString *)korobka objem_from:(NSString *)objem_from objem_to:(NSString *)objem_to kilo_from:(NSString *)kilo_from kilo_to:(NSString *)kilo_to kilo_od:(NSString *)kilo_od raztam:(NSString *)raztam bet:(NSString *)bet status_avto:(NSString *)status_avto credit:(NSString *)credit confiskat:(NSString *)confiskat not_go:(NSString *)not_go period:(NSString *)period sort:(NSString *)sort { User* UserAutoDetails; NSString *urlstring = [NSString stringWithFormat:@"%@b/index.php?category_avto=%@&kyzov_avto=%@&marka_avto=%@&model_avto=%@&year_avto1=%@&year_avto2=%@®ion_avto=%@&city_avto=%@&price_from=%@&price_to=%@&valuta_avto=%@&count_avto=%@&milage_from=%@&milage_to=%@&toplivo=%@&korobka=%@&objem_from=%@&objem_to=%@&kilo_from=%@&kilo_to=%@&kilo_od=%@&raztam=%@&bet=%@&status_avto=%@&credit=%@&confiskat=%@¬_go=%@&period=%@&sort=%@&photo_plus=%@&page=%ld&l=%@",CodeMunkeysWebAPIservice,category_avto,kyzov_avto,marka_avto,model_avto,year_avto1,year_avto2,region_avto,city_avto,price_from,price_to,valuta_avto, count_avto,milage_from,milage_to,toplivo,korobka,objem_from,objem_to,kilo_from,kilo_to,kilo_od,raztam,bet,status_avto,credit,confiskat,not_go,period,sort,photo_plus,(long)Pages,[[Localisator sharedInstance] currentLanguage]]; NSURL *URL = [NSURL URLWithString:[urlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSData *posturl = [NSData dataWithContentsOfURL:URL]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:URL]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; NSString *post = [NSString stringWithFormat:@""]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData]; //NSLog(@"Request: %@", request); NSURLResponse* response = nil; NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; if (data != nil) { NSError* jsonError; NSDictionary* json = [NSJSONSerialization JSONObjectWithData:posturl options:kNilOptions error:&jsonError]; // NSLog(@"%@",json); year = [json valueForKey:@"year"]; objem = [json valueForKey:@"objem"]; power = [json valueForKey:@"kilo"]; peredac=[json valueForKey:@"peredac"]; formula=[json valueForKey:@"privod"]; gruzpod=[json valueForKey:@"capacity"]; about = [json valueForKey:@"about_ad"]; prob = [json valueForKey:@"milage"]; id_auto = [json valueForKey:@"id_auto"]; fdate=[json valueForKey:@"fulldate"]; avtocount = [json valueForKey:@"counter"]; priced=[json valueForKey:@"price"]; pricee=[json valueForKey:@"pricee"]; priceg=[json valueForKey:@"priceg"]; model=[json valueForKey:@"model"]; date=[json valueForKey:@"date"]; allavto=[json valueForKey:@"total_avto"]; photos=[json valueForKey:@"photos"]; bigphotos=[json valueForKey:@"bigphotos"]; NSDictionary *markad=[json valueForKey:@"marka"]; marka=[markad valueForKey:@"marka"]; if ([[[Localisator sharedInstance] currentLanguage] isEqualToString:@"English_en"]) { myKyzov =@"kyzov_en"; mySos =@"count_part_en"; myToplivo=@"toplivo_en"; myTeh =@"category_en"; myKPP =@"korobka_en"; myCities =@"city_en"; myColor=@"color_en"; }else if ([[[Localisator sharedInstance] currentLanguage] isEqualToString:@"Russian_ru"]){ myKyzov =@"kyzov_ru"; mySos =@"count_part_ru"; myToplivo=@"toplivo_ru"; myTeh =@"category_ru"; myKPP =@"korobka_ru"; myCities =@"city"; myColor=@"color_ru"; }else if ([[[Localisator sharedInstance] currentLanguage] isEqualToString:@"Ukraine_uk"]){ myKyzov =@"kyzov_ua"; mySos =@"count_part_ua"; myToplivo=@"toplivo_ua"; myTeh =@"category_ua"; myKPP =@"korobka_ua"; myCities =@"city_ua"; myColor=@"color_ua"; } NSDictionary *soss=[json valueForKey:@"count_avto"]; sos=[soss valueForKey:[NSString stringWithFormat:@"%@",mySos]]; NSDictionary *n=[json valueForKey:@"id_user"]; name=[n valueForKey:[NSString stringWithFormat:@"name"]]; NSDictionary *inx=[json valueForKey:@"id_user"]; iduser=[inx valueForKey:[NSString stringWithFormat:@"id_user"]]; NSDictionary *t1=[json valueForKey:@"id_user"]; nomer=[t1 valueForKey:[NSString stringWithFormat:@"phone1"]]; NSDictionary *t2=[json valueForKey:@"id_user"]; nomer2=[t2 valueForKey:[NSString stringWithFormat:@"phone2"]]; NSDictionary *kilo=[json valueForKey:@"kilo_od"]; kilod=[kilo valueForKey:[NSString stringWithFormat:@"id_kilo"]]; NSDictionary *top=[json valueForKey:@"toplivo"]; pal=[top valueForKey:[NSString stringWithFormat:@"%@",myToplivo]]; NSDictionary *col=[json valueForKey:@"color"]; color=[col valueForKey:[NSString stringWithFormat:@"%@",myColor]]; NSDictionary *categ=[json valueForKey:@"category"]; teh=[categ valueForKey:[NSString stringWithFormat:@"%@",myTeh]]; NSDictionary *kyzovs=[json valueForKey:@"kyzov"]; kyzov=[kyzovs valueForKey:[NSString stringWithFormat:@"%@",myKyzov]]; NSDictionary *toplevo=[json valueForKey:@"korobka"]; kpp=[toplevo valueForKey:[NSString stringWithFormat:@"%@",myKPP]]; NSDictionary *cities=[json valueForKey:@"city"]; citys=[cities valueForKey:[NSString stringWithFormat:@"%@",myCities]]; //NSLog(@"%@",json); if(nil != jsonError) { NSLog(@"Error: %@", jsonError); } else { if (json) { for (NSDictionary* jsonDict in json) { User *user = [[User alloc] init]; [user setPhoto:[jsonDict objectForKey:@"photos"]]; [user setPhoto:[jsonDict objectForKey:@"bigphotos"]]; UserAutoDetails = user; } } else { NSLog(@"An error occurred: %@", jsonError); } } } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle: LOCALIZATION(@"Oops") message:LOCALIZATION(@"No connected") delegate: self cancelButtonTitle:nil otherButtonTitles:@"OK",nil]; [alert show]; }
return UserAutoDetails; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (_counter.hidden==YES) { return 0; }else{ return year.count; } }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AutoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"resaltauto" forIndexPath:indexPath]; if (cell == nil) { cell = [[AutoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"resaltauto"]; } NSArray *responseObjectData =year[indexPath.row]; NSArray *responsePriced =priced[indexPath.row]; NSArray *responsePricegrn =priceg[indexPath.row]; NSArray *responseModel =model[indexPath.row]; NSArray *responseMarka =marka[indexPath.row]; NSArray *responseDate =date[indexPath.row]; NSArray *responseKyzov =kyzov[indexPath.row]; NSArray *responseKpp =kpp[indexPath.row]; NSArray *responseCity =citys[indexPath.row]; NSArray* responsePhotos=photos[indexPath.row]; if (!!allavto) { totalavto=@"0"; } totalavto=allavto[0]; //NSLog(@"%@",[NSString stringWithFormat:@"%@",responsePhotos[0]]); if ([totalavto isEqualToString:@"0"]) { self.counter.text=@"0"; }else{ self.counter.text=totalavto; } cell.year.text=[NSString stringWithFormat:@"%@",responseObjectData]; cell.city.text=[NSString stringWithFormat:@"%@",responseCity]; cell.minicounter.text=[NSString stringWithFormat:@"%i",(NSUInteger)indexPath.row+1]; cell.date.text=[NSString stringWithFormat:@"%@",responseDate]; // cell.priced.text=[NSString stringWithFormat:@"%@%@ | %@$",responsePricegrn,LOCALIZATION(@"UAH"),responsePriced]; if ([responsePriced isEqual:@"-1"] || [responsePriced isEqual:@"0"]) { cell.priced.text=[NSString stringWithFormat:LOCALIZATION(@"negotiable")]; }else{ cell.priced.text=[NSString stringWithFormat:@"%@ %@",responsePricegrn,LOCALIZATION(@"UAH")]; } cell.toplivo.text=[NSString stringWithFormat:@"%@",responseKpp]; // cell.nazva.frame=CGRectMake(120, cell.nazva.frame.size.height*1.5, cell.nazva.frame.size.width, cell.nazva.frame.size.height); cell.lprice.frame=CGRectMake(135, cell.nazva.frame.size.height*4.2, cell.lprice.frame.size.width, cell.lprice.frame.size.height); cell.priced.frame=CGRectMake(180, cell.nazva.frame.size.height*4.2, cell.priced.frame.size.width, cell.priced.frame.size.height); cell.city.frame=CGRectMake(225, cell.nazva.frame.size.height*5, cell.city.frame.size.width, cell.city.frame.size.height); cell.ldate.frame=CGRectMake(10, cell.nazva.frame.size.height*5, cell.ldate.frame.size.width, cell.ldate.frame.size.height); cell.date.frame=CGRectMake(100, cell.nazva.frame.size.height*5, cell.date.frame.size.width, cell.date.frame.size.height); if ([cell.toplivo.text isEqual:@"<null>"]) { cell.toplivo.hidden=YES; cell.ltoplivo.hidden=YES; cell.year.frame=CGRectMake(225, cell.ldate.frame.size.height*2.7, cell.city.frame.size.width, cell.city.frame.size.height); cell.lyear.frame=CGRectMake(135, cell.ldate.frame.size.height*2.7, cell.city.frame.size.width, cell.city.frame.size.height); cell.kyzov.frame=CGRectMake(225, cell.ldate.frame.size.height*3.8, cell.kyzov.frame.size.width, cell.kyzov.frame.size.height); cell.lkyzov.frame=CGRectMake(135, cell.ldate.frame.size.height*3.8, cell.kyzov.frame.size.width, cell.kyzov.frame.size.height); }else{ cell.toplivo.hidden=NO; cell.ltoplivo.hidden=NO; cell.year.frame=CGRectMake(225, cell.ldate.frame.size.height*2.7, cell.city.frame.size.width, cell.city.frame.size.height); cell.lyear.frame=CGRectMake(135, cell.ldate.frame.size.height*2.7, cell.city.frame.size.width, cell.city.frame.size.height); cell.kyzov.frame=CGRectMake(225, cell.ldate.frame.size.height*3.8, cell.kyzov.frame.size.width, cell.kyzov.frame.size.height); cell.lkyzov.frame=CGRectMake(135, cell.ldate.frame.size.height*3.8, cell.kyzov.frame.size.width, cell.kyzov.frame.size.height); cell.toplivo.frame=CGRectMake(230, cell.ldate.frame.size.height*6, cell.city.frame.size.width, cell.city.frame.size.height); cell.ltoplivo.frame=CGRectMake(135, cell.ldate.frame.size.height*6, cell.city.frame.size.width, cell.city.frame.size.height);
}
if ([cell.city.text isEqual:@"<null>"]) { cell.city.hidden=YES; }else{ cell.city.hidden=NO; } cell.nazva.text=[NSString stringWithFormat:@"%@ %@",responseMarka,responseModel]; cell.kyzov.text=[NSString stringWithFormat:@"%@",responseKyzov];
dispatch_async(kBgQueue, ^{ dataimage = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",responsePhotos[0]]]]; if (dataimage) { UIImage *image = [UIImage imageWithData:dataimage]; if (image) { dispatch_async(dispatch_get_main_queue(), ^{ AutoTableViewCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath]; if (updateCell) updateCell.imgauto.image = image; }); } }
}); cell.lprice.text=[NSString stringWithFormat:LOCALIZATION(@"cena")]; cell.ldate.text=[NSString stringWithFormat:LOCALIZATION(@"Date of publication")]; cell.lyear.text=[NSString stringWithFormat:LOCALIZATION(@"godvypusk")]; cell.lkyzov.text=[NSString stringWithFormat:LOCALIZATION(@"typekyzov")]; cell.lcity.text=[NSString stringWithFormat:LOCALIZATION(@"city1")]; cell.ltoplivo.text=[NSString stringWithFormat:LOCALIZATION(@"kpp")]; cell.lminicount.text=[NSString stringWithFormat:LOCALIZATION(@"Auto №")]; return cell; }
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if(tableView ==self.searchDisplayController.searchResultsTableView){ [self performSegueWithIdentifier:@"kartavto" sender:self]; } } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([segue.identifier isEqualToString:@"kartavto"]){ KartkaViewController *destViewController = segue.destinationViewController; NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; destViewController.AvtoMarka = [marka objectAtIndex:indexPath.row]; destViewController.AvtoModel = [model objectAtIndex:indexPath.row]; destViewController.AvtoPrice = [priceg objectAtIndex:indexPath.row]; destViewController.AvtoPricee = [pricee objectAtIndex:indexPath.row]; destViewController.AvtoPriced = [priced objectAtIndex:indexPath.row]; destViewController.AvtoPhoto = [bigphotos objectAtIndex:indexPath.row]; destViewController.CounterView = [avtocount objectAtIndex:indexPath.row]; destViewController.AvtoProb = [prob objectAtIndex:indexPath.row]; destViewController.AvtoAbout = [about objectAtIndex:indexPath.row]; destViewController.AvtoSos = [sos objectAtIndex:indexPath.row]; destViewController.AvtoTeh = [teh objectAtIndex:indexPath.row]; destViewController.AvtoKyz = [kyzov objectAtIndex:indexPath.row]; destViewController.AvtoGod = [year objectAtIndex:indexPath.row]; destViewController.Date = [fdate objectAtIndex:indexPath.row]; destViewController.index = indexPath.row; destViewController.AvtoKPP = [kpp objectAtIndex:indexPath.row]; destViewController.AvtoToplivo = [pal objectAtIndex:indexPath.row]; destViewController.AvtoPower = [power objectAtIndex:indexPath.row]; destViewController.AvtoPeredac = [peredac objectAtIndex:indexPath.row]; destViewController.AvtoObjem = [objem objectAtIndex:indexPath.row]; destViewController.AvtoFormula = [formula objectAtIndex:indexPath.row]; destViewController.AvtoColor = [color objectAtIndex:indexPath.row]; destViewController.AvtoGruzpod = [gruzpod objectAtIndex:indexPath.row]; destViewController.AvtoKod = [kilod objectAtIndex:indexPath.row]; destViewController.AvtoCity = [citys objectAtIndex:indexPath.row]; destViewController.AvtoName = [name objectAtIndex:indexPath.row]; destViewController.AvtoNomer = [nomer objectAtIndex:indexPath.row]; destViewController.AvtoNomer2 = [nomer2 objectAtIndex:indexPath.row]; destViewController.iduser = [iduser objectAtIndex:indexPath.row]; } }
@end
|
|