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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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 />

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {<br />

return 1;<br />

}<br />

// Customize the number of rows in the table view.<br />

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

numberOfRowsInSection:(NSInteger)section {<br />

return [dataList getSize];<br />

}<br />

// Customize the appearance of table view cells.<br />

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

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

static NSString *CellIdentifier = @"Cell";<br />

UITableViewCell *cell = [tableView<br />

dequeueReusableCellWithIdentifier:CellIdentifier];<br />

if (cell == nil) {<br />

cell = [[[UITableViewCell alloc]<br />

initWithStyle:UITableViewCellStyleDefault<br />

reuseIdentifier:CellIdentifier] autorelease];<br />

}<br />

!<br />

! NSDictionary *itemAtIndex = (NSDictionary *)[dataList<br />

objectAtIndex:indexPath.row];<br />

! cell.textLabel.text = [itemAtIndex objectForKey:@"nome"];<br />

}<br />

return cell;<br />

I tre metodi sono i soliti che vanno inseriti quando si lavora con le UITableView. Concentriamoci<br />

un attimo sulle righe 22 e 23. Esse hanno il compito di ricavare un oggetto dalla lista “dataLista”<br />

(che contiene tutti i valori letti da database), <strong>per</strong> estrarne poi il nome desiderato (ovviamente<br />

vengono estratti tutti i nomi, dal primo all’ultimo). Potete vedere che dall’oggetto<br />

“itemAtIndex” viene estratto solo il nome: potremmo creare anche altre combinazioni, ad<br />

esempio con il cognome. Per fare ciò vi basterà modificare la riga 23 ad esempio nel seguente<br />

modo:<br />

1 [itemAtIndex objectForKey:@"cognome"];<br />

Abbiamo concluso la nostra applicazione! Clicchiamo su “Build and Go!” e controlliamo che<br />

funzioni tutto in maniera corretta.<br />

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

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

Saved successfully!

Ooh no, something went wrong!