Partage
  • Partager sur Facebook
  • Partager sur Twitter

récupéré les tweet et les mettre dans une tableview

Sujet résolu
    22 novembre 2012 à 22:26:16

    Bonjour,

    je débute dans le développement ios donc mon petit est :

    j'arrive a récupéré le flux de tweeter et mais ou j'ai du mal c'est pour mettre mon resultat dans ma tableview.

    Voici ce que j'ai fait deja

    secondView.m

    ACAccountStore *store = [[ACAccountStore alloc] init];
        ACAccountType *twitterAccountType =
        [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
       
        //  Request permission from the user to access the available Twitter accounts
        [store requestAccessToAccountsWithType:twitterAccountType
                                             withCompletionHandler:^(BOOL granted, NSError *error) {
                                                     if (!granted) {
                                                             // The user rejected your request
                                                             NSLog(@"User rejected access to the account.");
                                                            
                                                        /* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"not access to the account" message:@"User rejected access to the account." delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
                                                            
                                                             [alert show];
                                                             */
                                                            
                                                     }
                                                     else {
                                                             // Grab the available accounts
                                                             NSArray *twitterAccounts =
                                                             [store accountsWithAccountType:twitterAccountType];
                                                            
                                                             if ([twitterAccounts count] > 0) {
                                                                     // Use the first account for simplicity
                                                                     ACAccount *account = [twitterAccounts objectAtIndex:0];
                                                                    
                                                                     // Now make an authenticated request to our endpoint
                                                                     NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
                                                                     [params setObject:@"20" forKey:@"count"];
                                                                     [params setObject:@"1" forKey:@"include_entities"];
                                                                    
                                                                     //  The endpoint that we wish to call
                                                                     NSURL *url =
                                                                     [NSURL
                                                                      URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];
                                                                    
                                                                     //  Build the request with our parameter
                                                                     TWRequest *request =
                                                                     [[TWRequest alloc] initWithURL:url
                                                                                                             parameters:params
                                                                                                      requestMethod:TWRequestMethodGET];
                                                                    
                                                                     // Attach the account object to this request
                                                                     [request setAccount:account];
                                                                    
                                                                     [request performRequestWithHandler:
                                                                      ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                                                                              if (!responseData) {
                                                                                      // inspect the contents of error
                                                                                      NSLog(@"%@", error);
                                                                                     
                                                                              }
                                                                              else {
                                                                                      NSError *jsonError;
                                                                                      NSArray *timeline =
                                                                                      [NSJSONSerialization
                                                                                       JSONObjectWithData:responseData
                                                                                       options:NSJSONReadingMutableLeaves
                                                                                       error:&jsonError];              
                                                                                      if (timeline) {                                                
                                                                                              // at this point, we have an object that we can parse
                                                                                              NSLog(@"%@", timeline);
                                                                                             
                                                                                              //add tableView
                                                                                             
                                                                                             
                                                                                      }
                                                                                      else {
                                                                                              // inspect the contents of jsonError
                                                                                              NSLog(@"%@", jsonError);
                                                                                            
                                                                                      }
                                                                              }
                                                                      }];
                                                                    
                                                             } // if ([twitterAccounts count] > 0)
                                                     } // if (granted)
                                             }];
    

    secondView.h

    @interface SecondViewController : UIViewController
    - (IBAction)refresh:(id)sender;
    @property (weak, nonatomic) IBOutlet UITableView *tableView;
    @end
    


    Merci d'avance
    • Partager sur Facebook
    • Partager sur Twitter
      23 novembre 2012 à 1:35:12

      Quel est ton problème ?
      • Partager sur Facebook
      • Partager sur Twitter
        23 novembre 2012 à 10:02:19

        en gros je vois pas comment recupere mon tableau json qui est dans la variable timeline et le mettre dans ma tableView car j'ai essayer certain truc mais sa ne fonctionne pas.

        Merci d'avance
        • Partager sur Facebook
        • Partager sur Twitter
          23 novembre 2012 à 14:14:19

          Tu utilises la méthode JSONObjectWithData:options:error:, elle te renvoie rien?
          responseData vaut nil? Si oui peux-tu nous donner le log d'erreur?


          • Partager sur Facebook
          • Partager sur Twitter
            23 novembre 2012 à 14:47:25

            il n y a pas d'erreur juste un problème de conception car j'aimerais ajouter ce que je récupère dans ma variable pour ensuite les mettre dans mon table View
            • Partager sur Facebook
            • Partager sur Twitter
              23 novembre 2012 à 15:40:23

              Bah cherche un peu, on est pas là pour faire le boulot à ta place mais pour t'aider...
              A première vue tu as chercher bien loin: http://www.siteduzero.com/tutoriel-3-5 [...] bulaires.html
              • Partager sur Facebook
              • Partager sur Twitter
                23 novembre 2012 à 16:18:13

                POur ton info j'ai pas demander qu'on me donne la solution mais juste qu'on m'oriente.

                et merci pour le lien.
                • Partager sur Facebook
                • Partager sur Twitter
                  24 novembre 2012 à 17:31:49

                  Donc j'ai une petit souci je n'arrive pas a afficher on array dans ma tableView et je n'est pas d'erreur.

                  ma tableView je les crée a la main sans utiliser la classe UITableView.

                  voici mon .h

                  @interface ViewController : UIViewController
                  @property (weak, nonatomic) IBOutlet UITableView *tableView;
                  @property(nonatomic, retain) NSArray * maliste;
                  


                  et voici mon .m

                  @interface ViewController ()
                  
                  @end
                  
                  @implementation ViewController
                  @synthesize maliste;
                  
                  - (void)viewDidLoad
                  {  
                      [super viewDidLoad];
                  	// Do any additional setup after loading the view, typically from a nib.
                      maliste = [[NSArray alloc] initWithObjects:@"test",@"test2",@"test3", nil];
                         NSLog(@"%@", maliste);
                      
                  }
                  
                  - (void)didReceiveMemoryWarning
                  {
                      [super didReceiveMemoryWarning];
                      // Dispose of any resources that can be recreated.
                  }
                  #pragma mark - Table view data source
                  
                  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
                  {
                  
                      // Return the number of sections.
                      return 1;
                  }
                  
                  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
                  {
                  
                      // Return the number of rows in the section.
                      return [maliste 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];
                      }
                      
                      // Configure the cell...
                      NSLog(@"test %@", cell.textLabel.text = [maliste objectAtIndex:indexPath.row]);
                      return cell;
                  }
                  
                  @end
                  
                  • Partager sur Facebook
                  • Partager sur Twitter
                    3 décembre 2012 à 21:19:50

                    Je crois qu'il faut que tu crée ton array dans le init, pas dans le viewdidload. Au moment ou la vue se charge, le delegate du tableview a déjà chargé les données, donc il ne prend pas en compte ton array.
                    • Partager sur Facebook
                    • Partager sur Twitter

                    récupéré les tweet et les mettre dans une tableview

                    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                    • Editeur
                    • Markdown