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.

Nel file “Tweet.h” inseriamo il seguente codice:<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 />

#import <br />

@interface Tweet : NSObject {<br />

! NSString *testo;<br />

! NSString *user;<br />

! UIImage *immagine;<br />

}<br />

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

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

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

@end<br />

Abbiamo dichiarato tre elementi, come vi ho anticipato poco fa:<br />

1. testo, che conterrà il messaggio del tweet, il testo appunto;<br />

2. user, che conterrà l’username di chi ha inserito il tweet letto;<br />

3. immagine, è l’immmagine (l’avatar) dell’utente che ha lasciato il tweet.<br />

Niente di complicato quindi. Nel file “Tweet.m” dovrete solo implementare il metodo “dealloc”<br />

e inserire “@synthesize”:<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 />

#import "Tweet.h"<br />

@implementation Tweet<br />

@synthesize testo, user, immagine;<br />

-(void)dealloc{<br />

! [testo release];<br />

! [user release];<br />

! [immagine release];<br />

! [su<strong>per</strong> dealloc];<br />

}<br />

@end<br />

Ovviamente se intendete creare un client più complesso potrete aumentare i componenti di<br />

questa classe, oppure inserire dei metodi che eseguano qualche o<strong>per</strong>azione (ad esempio un controllo<br />

dei dati). Per questo tutorial, tuttavia, ci basteranno questi semplici elementi.<br />

DEFINIAMO LA CLASSE “SAMPLETWITTERCLIENTVIEWCON-<br />

TROLLER”<br />

È venuto finalmente il momento di implementare la classe che si occu<strong>per</strong>à di leggere la timeline<br />

di Twitter.<br />

Apriamo il file “SampleTwitterClientViewController.h” e inseriamo il seguente codice:<br />

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

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

Saved successfully!

Ooh no, something went wrong!