У меня есть переход с тремя переходами (см. Код ниже). Первый из кнопки. Это работает отлично. Второй, нажав на ячейку в виде таблицы. Это прекрасно работает. Третья кнопка является вспомогательной кнопкой в ячейке tableview. Это открывает правильный контроллер просмотра, но не передает ссылку на пациента, как я закодировал. Я подтвердил это с помощью инструкции NSLog в viewDidLoad нового контроллера представления, и он показывает, что пациент является нулевым.Не удается выполнить с помощью индикатора принадлежности
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"addPatient"]) {
// to add a new patient (selection segue)
UINavigationController *navigationController = segue.destinationViewController;
RXAddPatientViewController *addPatientViewController = (RXAddPatientViewController*)navigationController.topViewController;
Patient *addPatient = [NSEntityDescription insertNewObjectForEntityForName:@"Patient" inManagedObjectContext:[self managedObjectContext]];
addPatientViewController.addPatient = addPatient;
}
if ([[segue identifier] isEqualToString:@"toPrescriptions"]) {
// to view prescriptions for the selected patient (selection segue)
RXPrescriptionsViewController *prescriptionViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Patient *selectedPatient = (Patient*) [self.fetchedResultsController objectAtIndexPath:indexPath];
prescriptionViewController.selectedPatient = selectedPatient;
NSLog(@"Selected Patient is %@", selectedPatient.patientFirstName);
}
if ([[segue identifier] isEqualToString:@"editPatient"]) {
// to edit the selected patient (accessory action)
UINavigationController *navigationController = segue.destinationViewController;
RXEditPatientViewController *editPatientViewController = (RXEditPatientViewController*)navigationController.topViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Patient *editPatient = (Patient*) [self.fetchedResultsController objectAtIndexPath:indexPath];
// passing a reference to the editPatientViewController
editPatientViewController.editPatient = editPatient;
NSLog(@"Selected patient is %@", editPatient.patientFirstName);
}
}
Отлично. Спасибо миллион – user2076367
Просто реализовал ваш код, и он отлично работает. Ваше объяснение было также спонтанным, и теперь я имею в виду, что думаю об этом. Еще раз спасибо за ваш быстрый ответ :) – user2076367