所以我有 AppDelegate 方法尝试在 ViewController 方法中设置对象。我的 AppDelegate 如下所示:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
//Grab a reference to the UISplitViewController
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
PatientDetailViewController* patientDetailViewController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = patientDetailViewController;
//Grab a reference to the masterviewcontroller and get the first patient in the list.
UINavigationController *patientNavController = [splitViewController.viewControllers objectAtIndex:0];
PatientMasterTableViewController *patientMasterViewController = (PatientMasterTableViewController *)[patientNavController topViewController];
Patient* firstPatient = [[patientMasterViewController patientArray] objectAtIndex:0];
//Set it as the detailviews patient.
[patientDetailViewController setPatient:firstPatient];
//Set the detail's as the left's delegate.
patientMasterViewController.delegate = patientDetailViewController;
}
return YES;
}
并且设置对象的方法如下所示:
-(void)setPatient:(Patient *)patient
{
if (![self.patient isEqual:patient])
{
self.patient = patient;
//Update the UI to reflect the new patient selected from the list.
[self refreshUI];
}
}
我遇到的问题是setPatient方法将被停止调用,直到程序崩溃并且我不知道为什么。任何人都可以对此有所了解吗?
答案 0 :(得分:0)
此:
-(void)setPatient:(Patient *)patient
{
if (![self.patient isEqual:patient])
{
self.patient = patient;
//Update the UI to reflect the new patient selected from the list.
[self refreshUI];
}
}
应该是:
-(void)setPatient:(Patient *)patient
{
_patient = patient;
[self refreshUI];
}