1

有人可以详细说明如何使用它[button sendActionsForControlEvents:UIControlEventTouchUpInside];从不同的按钮单击中单击一个按钮。

  .m
  int i = 0;

- (IBAction)brain:(UIButton *)sender {
   //Brain of the operation
    i++;
   }


- (IBAction)subBrain:(UIButton *)sender {
  if(i > 1){
  /* Here if the brain had been prior clicked then when subBrain is 
  clicked, edit some variables and re-click the brain button 
  how would I go about this?!? Also is there a better way of doing this?*/
  [button sendActionsForControlEvents:UIControlEventTouchUpInside];
  }

  }

   .h
- (IBAction)brain:(UIButton *)sender;
- (IBAction)subBrain:(UIButton *)sender;
4

1 回答 1

1

在 iOS 中,您通常不会尝试触发 UI 中的其他 Button,而是直接触发 Button 所附加的功能。所以在你的情况下,你会打电话:

[self brain:nil]

或者更好的是,将按钮本身拖到 .h 文件中并创建一个新的引用插座,将其称为“brainButton”或其他名称。您可以在代码中引用“self.brainButton”,并且可以执行类似的操作

[self brain:self.brainButton] // if you need the sender
于 2013-08-28T17:13:19.677 回答