Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @interface KOMainViewController() <UITableViewDelegate, UITableViewDataSource, MKAnnotation>
  2.  
  3.  
  4. @property(nonatomic)MKMapView *mapView;
  5. @end
  6.  
  7. @implementation KOMainViewController
  8. @synthesize KOTableViewWithClients;
  9. @synthesize shops_array,coordinate,partners_info_array,logos,brand;
  10.  
  11. - (void)viewDidLoad {
  12.     [super viewDidLoad];
  13.     shops_array = [NSMutableArray array];
  14.     partners_info_array = [NSMutableArray array];
  15.     logos = [NSMutableArray array];
  16.     brand = [NSMutableArray array];
  17.  
  18.     [self getPartneFromServer];
  19.  
  20.     [self getDataFromServer];
  21.     self.mapView.delegate = self;
  22.     KOTableViewWithClients.delegate = self;
  23.     KOTableViewWithClients.dataSource = self;
  24.    
  25.    
  26.    
  27. }
  28.  
  29. - (void) getDataFromServer {
  30.    
  31.     [[Loyality_Coupons_Models sharedMyData]
  32.      getNewsWith:@"698"
  33.      onSuccess:^(NSArray *data) {
  34.          [shops_array addObjectsFromArray:data];
  35.          [self.KOTableViewWithClients reloadData];
  36.          NSLog(@"shops array  %@",shops_array);
  37.          
  38.    
  39.      } onFailure:^(NSError *error, NSInteger statusCode) {
  40.          NSLog(@"error = %@ code = %ld", [error localizedDescription], statusCode);
  41.      }];
  42.          
  43.    
  44.    
  45.    
  46. }
  47.  
  48. -(void) getPartneFromServer {
  49.    
  50.     [[Loyality_Coupons_Models sharedPartner]
  51.      getPartnersWith:@"698"
  52.      onSuccess:^(NSArray *data) {
  53.         [partners_info_array addObjectsFromArray:data];
  54.         [self.KOTableViewWithClients reloadData];
  55.         NSLog(@"partners_info_array  %@",partners_info_array);
  56.  
  57.     } onFailure:^(NSError *error, NSInteger statusCode) {
  58.         NSLog(@"error = %@ code = %ld", [error localizedDescription], statusCode);
  59.  
  60.     }];
  61.    
  62. }
  63.  
  64. - (IBAction)map_or_list:(id)sender {
  65.     if (self.segmentedMapList.selectedSegmentIndex == 0){
  66.        
  67.     }else if (self.segmentedMapList.selectedSegmentIndex == 1){
  68.        
  69.         MKMapView *mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
  70.         mapView.showsUserLocation = YES;
  71.         mapView.showsBuildings = YES;
  72.         [self.view addSubview:mapView];
  73.      
  74.        
  75.        
  76.  
  77.        
  78.  
  79.        
  80.        
  81.        
  82.     }
  83.    
  84. }
  85.  
  86.  
  87. - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
  88. {
  89.     MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
  90.     [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
  91.    
  92.     MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
  93.     point.coordinate = userLocation.coordinate;
  94.     point.title = @"hey";
  95.    
  96.     [self.mapView addAnnotation:point];
  97. }
  98.  
  99.  
  100.  
  101. - (void)didReceiveMemoryWarning {
  102.     [super didReceiveMemoryWarning];
  103.     // Dispose of any resources that can be recreated.
  104. }
  105.  
  106.  
  107.  
  108. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  109. {
  110.     return partners_info_array.count;
  111. }
  112.  
  113.  
  114. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  115.    
  116. //    KOMainCell *OKCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KOMainCell class]) forIndexPath:indexPath];
  117.    
  118.     UITableViewCell *OKCell = [KOTableViewWithClients dequeueReusableCellWithIdentifier:@"Cell"];
  119.    
  120.    
  121.     NSLog(@"partners array = %@",partners_info_array);
  122.     logos = [partners_info_array objectAtIndex:3];
  123.     brand = [partners_info_array objectAtIndex:2];
  124.     NSLog(@"logos = %@",logos);
  125.    
  126. //      [cell.backgroundImageView setImageWithURL:[NSURL URLWithString:[@"http://api-test.idiscount.by" stringByAppendingString:tempCoupon.imageURL]]];
  127.    
  128. //    [OKCell.KOImageLogo setImageWithURL:[NSURL URLWithString:[@"http://api-test.idiscount.by" stringByAppendingString:[logos objectAtIndex:2]]]];
  129.    
  130.     NSString *brands1_string = [brand objectAtIndex:0];
  131.     NSString *brands2_string = [brand objectAtIndex:1];
  132.     NSString *brands3_string = [brand objectAtIndex:2];
  133.  
  134.     NSArray *allBrands = [NSArray arrayWithObjects:brands1_string,brands2_string,brands3_string, nil];
  135.    
  136.     NSLog(@"all brands %lu",(unsigned long) allBrands.count);
  137.    
  138.    
  139.     OKCell.textLabel.text = [allBrands objectAtIndex:indexPath.row];
  140.  
  141.     NSLog(@"row %ld",(long)indexPath.row);
  142.     return OKCell;
  143.    
  144. }
  145.  
  146.  
  147.  
  148. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement