我将一个包含对象的 NSArray 传递到一个屏幕,其中对象属性显示在表格中。这些对象中的每一个都包含一个纬度属性和一个经度属性。我想实现一个功能,用户选择一个单元格(其中每个单元格代表 NSArray 中的一个对象),然后用户被带到另一个屏幕,在那里他们可以看到表示地图上对象位置的注释,以及代表用户的注释。我该怎么做呢?这是我的 RootViewController.m 类中的相关代码:
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
self.secondViewController = controller;
[controller release];
self.secondViewController.locationList = sortedLocations;
[[self navigationController] pushViewController:controller animated:YES];
我在 SecondViewController.m 中的相关代码如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"locationcell";
LocationTableViewCell *cell = (LocationTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[LocationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
Location *location = [locationList objectAtIndex:indexPath.row];
cell.locationName.text = location.name;
cell.locationAddress.text = location.address;
cell.locationDistance.text = location.distance;
return cell;
}
请记住,可见属性是名称、地址和距离,但位置对象还包含纬度和经度属性。我知道我必须创建一个名为 MapViewController 的新屏幕。但正如我所说,我真的不确定从屏幕上的表格到显示位置对象的地图和用户的位置。