그래서 AppDelegate 메서드를 사용하여 ViewController 메서드에서 개체를 설정하려고합니다. 내 AppDelegate에은 다음과 같습니다App 대리자가 반복적으로 메서드를 호출하는 중
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 방법은 비 정지를 호출 할 것입니다 프로그램이 충돌 할 때까지 나는 왜 그런지 전혀 모른다. 누구든지 이것에 대해 밝힐 수 있습니까?
네, 고전 무한 루프입니다. 'self.patient = patient'는'[self setPatient : patient]'를 호출하는 것과 같습니다. –
Patient 클래스에 isEqual :을 구현 했습니까? 그렇지 않다면, 그 전화는 당신이 기대하는대로하지 않을 수도 있습니다. –
@jshier의 호의적 성명 : 속성을 초기화 할 때 instanceVariable을 사용하는 것이 좋습니다 (Apple 기준). 위 코드는 한 번 더 호출해야합니다. 코드에 노이즈를 추가하는 것 이외에는 평등 확인이 많이 이루어질 것 같지 않습니다. –