0

私の目標は、正しいものbutton.titleLabel.textをビュー コントローラーの handleLongPress 関数に単純に送信することです。これは私の機能です:

- (IBAction)handleLongPress:(UILongPressGestureRecognizer *)sender {
    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
                                          initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 1.0;
    [self setUserIntendsToChangeUIsoTheUIisLockedUntilUserSelection:YES];
    NSLog(@"sender? %@", sender);
    if ([sender.view isKindOfClass:[UIButton class]]) {
        self.myButton = (UIButton *)sender.view;
        NSLog(@"!!!!! %@", self.myButton.titleLabel.text);
        [self.view addSubview:self.scrollPickerView];     
    }

}

これは、ボタン「H」、「Cl」、「C」などの参照アウトレット コレクションを作成したストーリーボードです。

ここに画像の説明を入力

各ボタンは に応答しますが、別のボタンを押したとしてもUILongPressGesture、記録されたメッセージNSLog(@"!!!!! %@", self.myButton.titleLabel.text);は常に同じ UIButton "C" を参照します。私は何を間違えましたか?各ボタンのタイトルを handleLongPress 関数に送信するにはどうすればよいですか?

4

1 に答える 1

1

私は前にこれに遭遇しました。Interface Builder には 1 しかありませんUILongPressGestureRecognizerUILongPressGestureRecognizerビューごとに個別の が必要です。UILongPressGestureRecognizerInterface Builder に表示されるのは、下部のバーにあるアイコンの長い行です。

補足として:

    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
                                          initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 1.0;

無駄なコードです。新しい変数を作成し、それに対して何もしません。

于 2014-08-17T21:02:25.660 に答える