在一個UITableViewController子類,還有一些方法需要以加載數據和處理行選擇時所要實現的:NSDictionary可以與iPhone上的TableView一起使用嗎?
- (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 2010-04-17 05:13:47
簡單的解決方案,但這幫了我很多! – stitz 2010-10-12 19:22:39