Question

I have a IBAction method which is called when a button touched. But when the UIViewController is called, that IBAction method is called first before viewdidload. I checked my code, there is nowhere that I call IBAction method specificly.

What is the reason that method called before viewdidload? Why does it happen?

Thank you. .h

 @interface VC_PatientInfo : M_SwipeInterface

.m

  @implementation VC_PatientInfo
    static M_PatientRow* patient;
    NSMutableArray*activeDrugList;
    NSInteger orderId;
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    +(NSInteger)getOrderId{
        return orderId;
    }
    +(void)setOrderId:(NSInteger)oId{
        orderId=oId;
    }
    - (void)viewDidLoad
    {
        orderId=0;
[super viewDidLoad];
        patient= [VC_PatientList getPatient];
        activeDrugList = [[NSMutableArray alloc]init];
        activeDrugList=[DAO_GetPatientActiveDrugs drug:[VC_Login getGuid] visit_id:[VC_PatientList getPatient].visit_id];
        if([VC_Login is_from_monitoring]){
            [DAO_InsertMonitoriingList patient:[VC_Login getGuid] pId:[self.pId_lbl.text integerValue]];
            [self.txt_monitoring setText:@"Takip Listemden Çıkar"];
            self.txt_monitoring.textColor= [UIColor redColor];

        }
        // Do any additional setup after loading the view.
    }

    +(NSMutableArray*)refreshActiveDrugs{

        activeDrugList=[DAO_GetPatientActiveDrugs drug:[VC_Login getGuid] visit_id:[VC_PatientList getPatient].visit_id];
        return activeDrugList;
    }
    +(NSMutableArray*)getActiveDrugList{
        return activeDrugList;
    }
    - (IBAction)call_DrugOrder:(id)sender {
        [Global setVC:@"vc_drugorder"];
        [self callVC];
    }
    - (IBAction)setMonitoringList:(id)sender {
        if([self.txt_monitoring.text isEqualToString:@"text1"]){
            [DAO_InsertMonitoriingList patient:[VC_Login getGuid] pId:[self.pId_lbl.text integerValue]];
            [self.txt_monitoring setText:@"text2"];
            self.txt_monitoring.textColor= [UIColor redColor];
        }else{
            [DAO_RemoveMonitoriingList patient:[VC_Login getGuid] pId:[self.pId_lbl.text integerValue]];
            [self.txt_monitoring setText:@"text1"];
            self.txt_monitoring.textColor= [Global colorWithHexString:@"99CC00"];
        }
    }


    - (IBAction)setViewSecret:(id)sender {
        if(self.viewSecret.frame.size.height==143 )
           [self.viewSecret setFrame:CGRectMake(self.viewSecret.frame.origin.x,
                                               self.viewSecret.frame.origin.y,
                                               self.viewSecret.frame.size.width,
                                               0)];
        else
            [self.viewSecret setFrame:CGRectMake(self.viewSecret.frame.origin.x,
                                                 self.viewSecret.frame.origin.y,
                                                 self.viewSecret.frame.size.width,
                                                 143)];

    }
    - (IBAction)goBack:(id)sender {
        [self dismissViewControllerAnimated:NO completion:nil];
    }
    - (IBAction)callAllergyVC:(id)sender {
        [Global setVC:@"vc_patientallergy"];
        [self callVC];
    }
    - (IBAction)callDiagnosisVC:(id)sender {
        [Global setVC:@"vc_patientdiagnosis"];
        [self callVC];
    }
    - (IBAction)callVCOldOrder:(id)sender {
        [Global setVC:@"vc_oldorder"];
        [self callVC];
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    @end
Was it helpful?

Solution

There are some things you can check, trying to solve this:

Callers

Go to the implementation of the method, and stand with the caret on on of the lines of code inside it. No on the top left corner of the main window click the small button with the black and gray rectangles (To the left of the arrows) and check if there is any place in your caode where someone is calling this method.

You won't see outlets here - so if the Callers option is gray (Like in the picture below) - You are good.

callers

Methods call stack

Try putting a breakpoint on the first line of the method implementation. When the breakpoint stops you code, look at the left in the Navigator pane, under the Debugger, you can see the exact order in which the methods called eachother to get to the call of your method. Most chances you will only need to just go one step back (Just click the line to see where it happens - btw this is kind of like a time-machine (or scope-machine?) where you can see what was the state of all the objects in your scope).

call stack

Property Outlets

Go the where the outlet is defined (in your .h or .m file) in click that tiny gray circle. This will show you all the outlet connections to that method/property (In the following picture I clicked a property but the beginning of method will be the same).

Property Outlets

NIB/Storyboard connections

Open you NIB/Storyboard file, and click the View Controller itself (The top item in the Document Outline chain on the left, another options is Ctrl+Shift+Mouse Click the view controller in the IB and choose the View Controller from the drop menu).

Storyboard

Now on the right (In the Utilities pane) go to the Connection Inspector (The most right one) to see all the connections to everything in the View Controller. Check you method to see if anything is connected that shouldn't be.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top