In una sottoclasse UITableViewController, ci sono alcuni metodi che devono essere attuate al fine di caricare i dati e gestire l'evento di selezione fila:È possibile utilizzare NSDictionary con TableView su iPhone?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; //there is only one section needed for my table view
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myList count]; //myList is a NSDictionary already populated in viewDidLoad method
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease ];
}
// indexPath.row returns an integer index,
// but myList uses keys that are not integer,
// I don't know how I can retrieve the value and assign it to the cell.textLabel.text
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Handle row on select event,
// but indexPath.row only returns the index,
// not a key of the myList NSDictionary,
// this prevents me from knowing which row is selected
}
come dovrebbe NSDictionary di lavorare con TableView?
Qual è il modo più semplice per ottenere questo risultato?
La tua soluzione è abbastanza semplice per me. – bobo
Soluzione semplice ma questo mi ha aiutato molto! – stitz