我试图在按钮操作时交换两个对象,但我无法让它工作。它是第一次交换,但下次当我单击按钮时,它会因 EXC_BAD_ACCESS 而崩溃。
这是代码
-(IBAction)swapLocation
{
CCLocDTO *tempDto = searchDTO.toDTO;
searchDTO.toDTO = searchDTO.fromDTO;
searchDTO.fromDTO = tempDto;
NSLog(@"From Location is %@",searchDTO.fromDTO.streetAddress); //it becomes empty on next button click
NSLog(@"To Location is %@",searchDTO.toDTO.streetAddress);
NSLog(@"From Special Location is %@",searchDTO.fromSpecialDTO.locationName);
NSLog(@"To Special Location is %@",searchDTO.toSpecialDTO.locationName);
[self.tableView reloadData];
}
我在 Search DTO(searchDTO) 中分配 fromDTO 和 toDTO。