我有一个解析 XML 并存储在 NSObject(“调用”)中的应用程序。然后我在数据中显示表格,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Call *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = currentCall.call_name;
cell.detailTextLabel.text = currentCall.location;
cell.accessoryType = UIButtonTypeRoundedRect;
return cell;
}
我的问题是,当我推送到详细视图控制器时,如何设置 didSelectRowAtIndexPAth 方法以访问所有对象属性?我曾经使用这种方式,它有效,但我确信这不是最有效的方式。谢谢您的帮助。
老办法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"indexPath = %d", indexPath.row);
Call *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row / 2];
self.currentCallTypeDetail = currentCall.currentCallType;
self.unitsDetail = currentCall.units;
self.locationDetail = currentCall.location;
self.countyDetail = currentCall.county;
self.stationDetail = currentCall.station;
self.fullcallnumberDetail = currentCall.fullcallnumber;
self.latitude = currentCall.latitude;
self.longitude = currentCall.longitude;
self.callTypeDetail = currentCall.callType;
self.callNumberDetail = currentCall.callnumber;
self.timeDetail = currentCall.time;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
CallTypeDetailController *vc = [storyboard instantiateViewControllerWithIdentifier:@"calltypedetail"];
[vc setCurrentCallTypeDetail:self.currentCallTypeDetail];
[vc setUnitsDetail:self.unitsDetail];
[vc setLocationDetail:self.locationDetail];
[vc setCountyDetail:self.countyDetail];
[vc setStationDetail:self.stationDetail];
[vc setFullcallnumberDetail:self.fullcallnumberDetail];
[vc setCallTypeDetail:self.callTypeDetail];
[vc setCallNumberDetail:self.callNumberDetail];
[vc setTimeDetail:self.timeDetail];
[vc setLatitude:self.latitude];
[vc setLongitude:self.longitude];
[self.navigationController pushViewController:vc animated:YES];
NSLog(@"Selected Call = %@", self.currentCallTypeDetail);
}