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

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




secondView.h
<br />
@interface SecondViewController : UIViewController<br />
- (IBAction)refresh:(id)sender;<br />
@property (weak, nonatomic) IBOutlet UITableView *tableView;<br />
@end<br />




Merci d'avance.

Réponses

  • je te conseille de suivre les tutos proposés par Apple sur les UITableView avant de vouloir directement importer des infos de twitter !

    comprendre le mécanisme de délégation et les protocoles me semble le minimum

    et apprendre à  utiliser les fichiers XIB



    en gros, fais-toi les dents sur un projet simple qui contient au moins une table view



    cherche UITableView dans la doc Apple tu vas y trouver des exemples plus tôt bien faits.
  • Merci bien pour ta réponse.
  • christophe93christophe93 Membre
    novembre 2012 modifié #4
    Bonsoir,



    J'ai un petit souci pour afficher mon json de twitter et je ne vois pas ce que j'ai oublier.



    et j'ai aucune erreur qui s'affiche.



    j'ai testé mon tableView en créant des donnée et la j'arrive bien a afficher dans ma tableView mais aussitôt que je mais ma variable timeline rien ne se rempli, mais quand je fait un NSLog(@%@",timeline) il me renvoi bien mon array .



    voici mon .h
    <br />
    @property (weak, nonatomic) IBOutlet UITableView *tableView;<br />
    @property(nonatomic, retain) NSArray * timeline;<br />
    




    voici mon .m
    <br />
    #import &quot;SecondViewController.h&quot;<br />
    #import &quot;UIImageView+AFNetworking.h&quot;<br />
    @interface SecondViewController ()<br />
    @end<br />
    @implementation SecondViewController<br />
    @synthesize timeline;<br />
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil<br />
    {<br />
    	self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];<br />
    	if (self) {<br />
    		self.title = NSLocalizedString(@&quot;Second&quot;, @&quot;Second&quot;);<br />
    		self.tabBarItem.image = [UIImage imageNamed:@&quot;second&quot;];<br />
    	}<br />
    	return self;<br />
    }<br />
    	  <br />
    - (void)viewDidLoad<br />
    {<br />
    	[super viewDidLoad];<br />
      <br />
    // Do any additional setup after loading the view, typically from a nib.<br />
      <br />
    	//  First, we need to obtain the account instance for the user&#39;s Twitter account<br />
      <br />
    	ACAccountStore *store = [[ACAccountStore alloc] init];<br />
    	ACAccountType *twitterAccountType =<br />
    	[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];<br />
      <br />
    	//  Request permission from the user to access the available Twitter accounts<br />
    	[store requestAccessToAccountsWithType:twitterAccountType<br />
    					 withCompletionHandler:^(BOOL granted, NSError *error) {<br />
    						 if (&#33;granted) {<br />
    							 // The user rejected your request<br />
    							 NSLog(@&quot;User rejected access to the account.&quot;);<br />
    							<br />
    							/* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&quot;not access to the account&quot; message:@&quot;User rejected access to the account.&quot; delegate:nil cancelButtonTitle:@&quot;Cancel&quot; otherButtonTitles:nil, nil];<br />
    							<br />
    							 [alert show];<br />
    							 */<br />
    							<br />
    						 }<br />
    						 else {<br />
    							 // Grab the available accounts<br />
    							 NSArray *twitterAccounts =<br />
    							 [store accountsWithAccountType:twitterAccountType];<br />
    							<br />
    							 if ([twitterAccounts count] &gt; 0) {<br />
    								 // Use the first account for simplicity<br />
    								 ACAccount *account = [twitterAccounts objectAtIndex:0];<br />
    								<br />
    								 // Now make an authenticated request to our endpoint<br />
    								 NSMutableDictionary *params = [[NSMutableDictionary alloc] init];<br />
    								 [params setObject:@&quot;3&quot; forKey:@&quot;count&quot;];<br />
    								 [params setObject:@&quot;1&quot; forKey:@&quot;include_entities&quot;];<br />
    								<br />
    								 //  The endpoint that we wish to call<br />
    								 NSURL *url =<br />
    								 [NSURL<br />
    								  URLWithString:@&quot;http://api.twitter.com/1/statuses/home_timeline.json&quot;];<br />
    								<br />
    								 //  Build the request with our parameter<br />
    								 TWRequest *request =<br />
    								 [[TWRequest alloc] initWithURL:url<br />
    													 parameters:params<br />
    												  requestMethod:TWRequestMethodGET];<br />
    								<br />
    								 // Attach the account object to this request<br />
    								 [request setAccount:account];<br />
    								<br />
    								 [request performRequestWithHandler:<br />
    								  ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {<br />
    									  if (&#33;responseData) {<br />
    										  // inspect the contents of error<br />
    										  NSLog(@&quot;%@&quot;, error);<br />
    										<br />
    									  }<br />
    									  else {<br />
    										  NSError *jsonError;<br />
    										  timeline =<br />
    										  [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves<br />
    										   error:&amp;jsonError];		  <br />
    										  if (timeline) {						<br />
    											  // at this point, we have an object that we can parse<br />
    											  NSLog(@&quot;test :%@&quot;, timeline);<br />
    											<br />
    											<br />
    										  }<br />
    										  else {<br />
    											  // inspect the contents of jsonError<br />
    											  NSLog(@&quot;%@&quot;, jsonError);<br />
    											<br />
    										  }<br />
    									  }<br />
    								  }];<br />
    								<br />
    							 } // if ([twitterAccounts count] &gt; 0)<br />
    						 } // if (granted)<br />
    					 }];<br />
      <br />
    }<br />
    <br />
    - (void)didReceiveMemoryWarning<br />
    {<br />
    	[super didReceiveMemoryWarning];<br />
    	// Dispose of any resources that can be recreated.<br />
    }<br />
    <br />
    - (IBAction)refresh:(id)sender {<br />
      <br />
    }<br />
    //methode pour la tableView<br />
    #pragma mark - Table view data source<br />
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView<br />
    {<br />
      <br />
    	// Return the number of sections.<br />
    	return 1;<br />
    }<br />
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section<br />
    {<br />
      <br />
    	// Return the number of rows in the section.<br />
    	return [timeline count];<br />
    }<br />
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath<br />
    {<br />
    	static NSString *CellIdentifier = @&quot;TwitteCell&quot;;<br />
    	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];<br />
    	if (cell == nil) {<br />
    		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];<br />
    	}<br />
      <br />
    	// Configure the cell...<br />
    	NSDictionary *current = [ timeline objectAtIndex:indexPath.row];<br />
      <br />
    	cell.textLabel.text =   [current objectForKey:@&quot;user&quot;];<br />
    	cell.detailTextLabel.text = [current objectForKey:@&quot;text&quot;];<br />
    	[cell.imageView setImageWithURL:[NSURL URLWithString:current[@&quot;profile_image_url&quot;]]];<br />
      <br />
      <br />
    	return cell;<br />
    }<br />
    <br />
    @end<br />
    




    merci d'avance
  • Franchement... vu comment tu post ça ne donne pas envie de répondre :

    - Tu n'expliques pas exactement quel est ton soucis

    - Tu ne dis pas ce que tu as essayé



    À nous de nous débrouiller avec tout ton code ?

    Sans moi.
Connectez-vous ou Inscrivez-vous pour répondre.