Programmatically fire button click event?

后端 未结 5 1209
后悔当初
后悔当初 2020-12-04 07:36

Is there a way to programmatically fire a button click event? I have a button placed there in an UIView, and in a particular scenario i want to click the button via code, no

5条回答
  •  死守一世寂寞
    2020-12-04 08:28

    Why not just execute the code that executes when the user presses the button?

    -(void)myMethod
    {
       // do stuff
    }
    
    -(IBAction)myButtonClick:(id)sender
    {
        [self myMethod];
    }
    
    -(void)clickMyButton
    {
        [self myMethod];
        // OR
        [self myButtonClick:nil];
    }
    

提交回复
热议问题