В подклассе UITableViewController, есть некоторые методы, которые должны быть выполнены для того, чтобы загрузить данные и обрабатывать событие выбора строки:Может ли NSDictionary использоваться с TableView на 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
}
Как NSDictionary предполагается работать с TableView?
Каков самый простой способ сделать это?
Ваше решение достаточно просто для меня. – bobo
Простое решение, но это очень помогло мне! – stitz