Trong một lớp con UITableViewController, có một số phương pháp mà cần phải được thực hiện để tải dữ liệu và xử lý các sự kiện lựa chọn hàng:NSDictionary có thể được sử dụng với TableView trên iPhone không?
- (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
}
như thế nào NSDictionary vụ phải làm việc với TableView?
Cách đơn giản nhất để thực hiện việc này là gì?
Giải pháp của bạn đủ đơn giản đối với tôi. – bobo
Giải pháp đơn giản nhưng điều này đã giúp tôi rất nhiều! – stitz