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.

Questo metodo viene richiamato ogni volta che si “clicca” su una cella. Sarà qui che andremo<br />

ad inserire il codice necessario:<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 />

- (void)tableView:(UITableView *)tableView<br />

didSelectRowAtIndexPath:(NSIndexPath *)indexPath {<br />

! // ricaviamo il link dell'elemento selezionato<br />

! NSString *link = [[elencoFeed objectAtIndex:indexPath.row] objectForKey:<br />

@"link"];<br />

!<br />

! // ripuliamo il link da spazi, return e tabs<br />

! link = [link stringByReplacingOccurrencesOfString:@" "<br />

withString:@""];<br />

! link = [link stringByReplacingOccurrencesOfString:@"\n"<br />

withString:@""];<br />

! link = [link stringByReplacingOccurrencesOfString:@"! "<br />

withString:@""];<br />

!<br />

! // apriamo la notizia in Safari<br />

! [[UIApplication sharedApplication] openURL:[NSURL<br />

URLWithString:link]];<br />

}<br />

Il procedimento è molto simile a quello visto <strong>per</strong> la definizione delle celle della tabella. Alla riga<br />

4, infatti, andiamo a ricavare la proprietà “link” dell’elemento selezionato, associandola ad<br />

una stringa chiamata appunto “link”. Con le istruzioni seguenti, invece, ripuliamo l’indirizzo da<br />

eventuali caratteri indesiderati, come spazi, return o tab. Con l’istruzione alla riga 12, infine,<br />

apriamo Safari passandogli come parametro proprio il link da noi voluto (che deve essere trasformato<br />

in un NSURL). Fatto!<br />

Salvate il tutto, cliccate su “Build and Run” e godetevi la vostra bellissima applicazione!!<br />

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

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

Saved successfully!

Ooh no, something went wrong!