0

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);
} 
4

1 に答える 1

0
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"indexPath = %d", indexPath.row);

Call *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row / 2];

[tableView deselectRowAtIndexPath:indexPath animated:YES];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
CallTypeDetailController *vc = [storyboard instantiateViewControllerWithIdentifier:@"calltypedetail"];

[vc setCurrentCall:currentCall];

[self.navigationController pushViewController:vc animated:YES];

NSLog(@"Selected Call = %@", self.currentCallTypeDetail);
} 
于 2012-10-31T20:28:41.513 に答える