簡體   English   中英

應用委托重復調用方法

[英]App delegate calling method repeatedly

所以我有我的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方法將被稱為不停止,並且我不知道為什么。 誰能對此有所啟發?

這個:

-(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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM