récupéré les tweet et les mettre dans une tableview
christophe93
Membre
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
secondView.h
Merci d'avance.
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 (!granted) {<br />
// The user rejected your request<br />
NSLog(@"User rejected access to the account.");<br />
<br />
/* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"not access to the account" message:@"User rejected access to the account." delegate:nil cancelButtonTitle:@"Cancel" 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] > 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:@"20" forKey:@"count"];<br />
[params setObject:@"1" forKey:@"include_entities"];<br />
<br />
// The endpoint that we wish to call<br />
NSURL *url =<br />
[NSURL<br />
URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];<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 (!responseData) {<br />
// inspect the contents of error<br />
NSLog(@"%@", error);<br />
<br />
}<br />
else {<br />
NSError *jsonError;<br />
NSArray *timeline =<br />
[NSJSONSerialization<br />
JSONObjectWithData:responseData<br />
options:NSJSONReadingMutableLeaves<br />
error:&jsonError]; <br />
if (timeline) { <br />
// at this point, we have an object that we can parse<br />
NSLog(@"%@", timeline);<br />
<br />
//add tableView<br />
<br />
<br />
}<br />
else {<br />
// inspect the contents of jsonError<br />
NSLog(@"%@", jsonError);<br />
<br />
}<br />
}<br />
}];<br />
<br />
} // if ([twitterAccounts count] > 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.
Connectez-vous ou Inscrivez-vous pour répondre.
Réponses
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.
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
voici mon .m
merci d'avance
- 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.