Magazine

Tutoriel sur la conception d’un lecteur de flux RSS simple : Téléchargement et utilisation des feeds

Publié le 19 juillet 2011 par Developpementiphone

mots-clés : developpement iphone, tutoriel, lecteur rss
Pour terminer

Nous avons besoin de couper toute fuite de mémoire potentielle (c’est une bonne habitude à prendre en, quand vous n’avez pas de collecte des ordures – qui a besoin que de toute façon). Ajoutez ce changement:

- (void)dealloc {
[currentElement release];
[rssParser release];
[stories release];
[item release];
[currentTitle release];
[currentDate release];
[currentSummary release];
[currentLink release];
[super dealloc];
}

Ensuite, ouvrez “RootViewController.xib”, et maintenez la touche “contrôle” de votre clavier, tout en faisant glisser l’icône en cube du “RootViewController” vers la table view (sur Xcode 3). Vous devriez voir une liste de trois éléments apparaître, cliquez sur l’élément “newsTable”. Sauvegardez et quittez l’Interface Builder.

Compiler et lancer

Si vous cliquez sur “Build and Go”,  vous verrez le résultat de ce que nous avons fait. Si vous le lancez sur un iPhone et non dans le simulateur, le résultat serait légèrement différent : l’appareil est plus lent, et si vous êtes en connection EDGE, le feed RSS prendra très longtemps à se télécharger. Mais, après tout, ça marche!
Une chose qui ne fonctionne pas encore : quand vous appuyez sur un objet de la table, If you were to run this on an actual iPhone and not in simulator, the results would be different slightly: the hardware is slower, and if you’re on EDGE, the RSS feed will take a very long time to download. But, hey, it works! One thing that doesn’t work yet: when you tap on an item in the table, il ne se passe rien. C’est le comportement par défaut, mais ouvrons stories dans Safari – c’est une chose facile à faire.Changez juste cette méthode :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic int storyIndex = [indexPath indexAtPosition: [indexPath length] – 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @”link”];
// clean up the link – get rid of spaces, returns, and tabs… storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@”link: %@”, storyLink);
// open in Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]]; }

Maintenant, cliquez de nouveau sur “Build and Go”, pour voir que ça fonctionne.


Retour à La Une de Logo Paperblog

Dossier Paperblog