0

addTarget:Action:forControlEventsを使用しようとしていますが、認識されないセレクターの実行時例外を受け取ります。

これは、 initWithFrameのUIViewサブクラスから呼び出されています。以下は私のコードです:

myButton = [[UIButton alloc] initWithFrame:frame];
[myButton addTarget:self action:&selector(displayList:)
                         forControlEvents:UIControlEventTouchUpInside];

私の方法:

-(void)displayList:(id)sender

ボタンをクリックすると、次のメッセージが表示されます。

-[MyClass displayList:]: unrecognized selector sent to instance. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: -[MyClass displayList:]: unrecognized selector sent to instance.

MyClassは、 UIButtonおよびUILabelを持つUIViewサブクラスであるカスタム コントロールです。このクラスは、別のアプリケーションの ViewController に配置されます。

何が欠けているのかわかりません。どんな助けでも大歓迎です。

4

2 に答える 2

2

それは読むべきです

[myButton addTarget:self action:@selector(displayList:) forControlEvents:UIControlEventTouchUpInside];

@ それ以外の &

于 2012-04-17T14:13:52.170 に答える
0
[myButton addTarget:self action:&selector(displayList:) forControlEvents:UIControlEventTouchUpInside];

構文は @selector(displayList:) です
。また、変更によってボタンがイベントを発生させない場合があります。この方法で作成してみてください:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //this will return an autoreleased UIButton object, be careful.
button.frame = CGRectMake(...);
...
于 2012-04-17T14:14:35.033 に答える