What's the best way to call an IBAction from with-in the code?

前端 未结 2 682
眼角桃花
眼角桃花 2020-12-15 16:22

Say for instance I have an IBAction that is hooked up to a UIButton in interface builder.

- (IBAction)functionToBeCalled:         


        
2条回答
  •  盖世英雄少女心
    2020-12-15 16:50

    The proper way is either:

    - [self functionToBeCalled:nil] 
    

    To pass a nil sender, indicating that it wasn't called through the usual framework.

    OR

    - [self functionToBeCalled:self]
    

    To pass yourself as the sender, which is also correct.

    Which one to chose depends on what exactly the function does, and what it expects the sender to be.

提交回复
热议问题