20.04.2013 Views

Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog

Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog

Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PARTE 3: IL SALVATAGGIO DEI DATI<br />

In questa terza e ultima parte vedremo come utilizzare la classe NSUserDefault, che ci <strong>per</strong>mette<br />

di salvare delle informazioni relative alla nostra applicazione. Quello che andremo a salvare<br />

sarà la data in cui è stato eseguito l’ultimo refresh della timeline, che mostreremo all’avvio<br />

all’utente.<br />

Ovviamente questa è una semplificazione, in applicazioni più complesse potremmo avere molte<br />

più informazioni da memorizzare (ad esempio dei settaggi come l’autorefresh, il nome utente o<br />

la password). Analizzeremo, quindi, solo il salvataggio di un parametro, ma vedrete che non sarà<br />

nulla di difficile!<br />

La prima cosa da fare è inserire una label in cui venga visualizzata l’ultima data in cui è stato<br />

eseguito un refresh della nostra timeline.<br />

Nel file “SampleTwitterClientViewController.h” inseriamo la seguente dichiarazione (righe 12 e<br />

24):<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

17<br />

18<br />

19<br />

20<br />

21<br />

22<br />

23<br />

24<br />

25<br />

26<br />

#import <br />

#import "MGTwitterEngine.h"<br />

@class Tweet;<br />

@class TabellaTwitterViewController;<br />

@interface SampleTwitterClientViewController : UIViewController<br />

{<br />

! MGTwitterEngine *twitterEngine;<br />

! NSMutableArray *listaTweet;<br />

!<br />

! IBOutlet UIActivityIndicatorView *spinner;<br />

! IBOutlet UILabel *labelUltimoRefresh;<br />

!<br />

! TabellaTwitterViewController *tabellaTwitterViewController;<br />

}<br />

-(NSString*)getMessaggio:(NSDictionary*)element;<br />

-(NSString*)getUser:(NSDictionary*)element;<br />

-(NSURL*)getUrlImage:(NSDictionary*)element;<br />

@pro<strong>per</strong>ty (nonatomic, retain) NSMutableArray *listaTweet;<br />

@pro<strong>per</strong>ty (nonatomic, retain) IBOutlet UIActivityIndicatorView<br />

*spinner;<br />

@pro<strong>per</strong>ty (nonatomic, retain) IBOutlet TabellaTwitterViewController<br />

*tabellaTwitterViewController;<br />

@pro<strong>per</strong>ty (nonatomic, retain) IBOutlet UILabel *labelUltimoRefresh;<br />

@end<br />

Salviamo il file e apriamo poi “SampleTwitterClientViewController.xib”, che aprirà IB. Inserite<br />

una o due label (a vostro piacere), io ho fatto così:<br />

<strong>Tutorial</strong> <strong>pratici</strong> <strong>per</strong> <strong>iPhone</strong> <strong>SDK</strong>! 157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!