私のxibファイルには2つのボタンがあります。これは私のインターフェースファイルです
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *testButtonOut;
@property (strong, nonatomic) IBOutlet UIButton *button2;
- (IBAction)testButton:(id)sender;
- (void)buttonReleased;
@end
これらは、実装ファイル内の 2 つの関数の実装です
- (IBAction)testButton:(id)sender {
button2.highlighted=YES;
[testButtonOut addTarget:self action:@selector(buttonReleased) forControlEvents:UIControlEventTouchCancel];
}
- (void)buttonReleased{
button2.highlighted=NO;
}
testButton をクリックして放しても、buttonReleased 関数はトリガーされません (ブレークポイントを使用して確認しました)。ただし、UIControlEventTouchCancel を UIControlEventTouchUpInside に変更すると、クリックしたときに buttonReleased 関数がトリガーされますが、トリガーしたくありません。ボタンのクリックでボタンを離したときにトリガーしたいのですが、TouchUpOutsideでも試しましたが、トリガーしませんでした。 ボタン イベントからクリックを離したときに buttonReleased 関数を呼び出すには、どのイベントを使用すればよいですか?