// // ScanHomeViewController.m // HMLG Scan Order // // Created by Rui Zhang on 5/12/22. // Copyright © 2022 United Software Applications, Inc. All rights reserved. // #import "ScanHomeViewController.h" #import "ScanHomeCell.h" #import "AppDelegate.h" #import "MainViewController.h" #import "WebViewController.h" @interface ScanHomeViewController () @end @implementation ScanHomeViewController - (void)viewDidLoad { [super viewDidLoad]; self.table.layer.borderColor = [UIColor darkGrayColor].CGColor; self.table.layer.borderWidth = 1.0; // [self loadNewsList]; // Do any additional setup after loading the view. } - (void) reload_data { DebugLog(@"ScanHomeViewController RELOAD"); [self loadNewsList]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.newslist.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 44; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ScanHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ScanHomeCell"]; if (!cell) { cell = [[ScanHomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScanHomeCell"]; } // NSArray* arr = self.newslist; cell.labeltitle.text = self.newslist[indexPath.row][@"title"]; cell.labeldate.text = self.newslist[indexPath.row][@"date"]; [cell.btnview addTarget:self action:@selector(onview:) forControlEvents:UIControlEventTouchUpInside]; // [cell setModelJson:arr[indexPath.row]]; return cell; } -(void) onview:(id)sender { UIButton* b = sender; ScanHomeCell *cell = (ScanHomeCell*)b.superview.superview; NSIndexPath* indexPath=[self.table indexPathForCell:cell]; NSString* url = self.newslist[indexPath.row][@"url"]; NSString* title = self.newslist[indexPath.row][@"title"]; WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"]; ViewController.url = url; ViewController.title = title; [self.navigationController pushViewController:ViewController animated:YES]; } - (IBAction)onCreateOrder:(id)sender { AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate; MainViewController * mainvc = (MainViewController*)appDelegate.main_vc; [ActiveViewController Notify:@"ScanOrderListViewController" Message:@"NewOrder"]; [mainvc switchToCart]; } - (IBAction)onSubmit:(id)sender { AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate; MainViewController * mainvc = (MainViewController*)appDelegate.main_vc; [ActiveViewController Notify:@"ScanOrderListViewController" Message:@"ShowSubmit"]; [mainvc switchToOrder]; } - (IBAction)onUnsubmit:(id)sender { AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate; MainViewController * mainvc = (MainViewController*)appDelegate.main_vc; [ActiveViewController Notify:@"ScanOrderListViewController" Message:@"ShowUnSubmit"]; [mainvc switchToOrder]; } -(void) loadNewsList { { [RADataProvider request_scan_news:^(NSMutableDictionary *result) { NSMutableDictionary* return_json = result; { if([[return_json valueForKey:@"result"] intValue]==2) { self.newslist = return_json[@"newslist"]; [self.table reloadData]; // if(self.newslist.count>0) // { // // } } else { self.newslist = [NSArray new]; [self.table reloadData]; } } }]; } } @end