Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // Ski
- //
- // Created by Administrateur on 15/11/2014.
- // Copyright (c) 2014 Administrateur. All rights reserved.
- //
- #import "ViewController.h"
- #import "ViewController2.h"
- @interface ViewController () {
- NSArray *pays;
- NSArray *pays2;
- }
- @property (weak, nonatomic) IBOutlet UITableView *tablePays;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- pays = @[@"France",@"Mexique",@"Suisse",@"Italie"];
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
- NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/pays.php"];
- NSURLRequest *requete = [NSURLRequest requestWithURL:url];
- [NSURLConnection sendAsynchronousRequest:requete
- queue:[NSOperationQueue mainQueue]
- completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
- {
- pays2 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
- NSLog(@"%@", pays2);
- [_tablePays reloadData];
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
- }
- ];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark UITableViewDataSource
- // Les methodes <UITableViewDataSource>
- //La classe viewController est configurée comme DataSource delegate de la tableview
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return pays2.count;
- }
- - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- //reutilisé une cellule existante?
- UITableViewCell *cellule = [tableView dequeueReusableCellWithIdentifier:@"stock"];
- if (!cellule) {//creation d'une nouvelle fenetre avec style et identifiant
- cellule = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"stock"];
- }
- //indexPath.row : n° de ligne de tableview
- cellule.textLabel.text = pays2[indexPath.row][@"Pays"];
- cellule.accessoryType = UITableViewCellAccessoryDetailButton;
- //image
- cellule.imageView.image =
- [UIImage imageWithData:
- [NSData dataWithContentsOfURL:
- [NSURL URLWithString:
- [NSString stringWithFormat:@"http://127.0.0.1/flags/%@.png", pays2[indexPath.row][@"code"]]]]];
- return cellule;
- }
- - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
- NSLog(@"Ligne %ld", indexPath.row);
- [self performSegueWithIdentifier:@"liaison" sender:self];
- }
- //prepare la liaison
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- //on recupere la vue de destination
- ViewController2 *view = (ViewController2 *)segue.destinationViewController;
- //On regle la propriete @property code_pays de ViewController2
- view.code_pays = @"FR";
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement