私は、入力としてstickerURLStringを受け取るデリゲートメソッドの下にこれを持っている:ボタンセレクタで文字列パラメータを別のメソッドに渡すにはどうすればいいですか?
- (void)selectedSticker:(NSString *)stickerURLString {
//...
[self.stickerPreviewButton addTarget:self action:@selector(sendStickerPreviewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
//...
}
そして、セレクタは、この方法が sendStickerPreviewButtonPressed呼び出します。あなたはこの作品を作るために見ることができるように
- (void)sendStickerPreviewButtonPressed: (NSString *)stickerURLString {
[self.delegate InputFunctionView:self sendSticker:stickerURLString];
}
を私は渡す必要があります期待通りにstickerURLStringから選択されたステッカーメソッドsendStickerPreviewButtonPressed。これに代えて
[self.stickerPreviewButton performSelector:@selector(sendStickerPreviewButtonPressed:) withObject:stickerURLString];
:
私はこれを試してみました
[self.stickerPreviewButton addTarget:self action:@selector(sendStickerPreviewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
をしかし、私はエラー "タイプNSExceptionのキャッチされない例外で終了する" しまいました。
誰もボタンセレクタで文字列パラメータを別のメソッドに渡す方法を知っていますか?あなたは、あなたがこの変化を使用することができる機能を呼び出すためにperformSelectorを使用している場合
(http://stackoverflow.com/questions/24814646/attach-parameter-to-button-addtarget-action-in-swift)スイフトでbutton.addTargetアクションにパラメータを添付]の可能な重複 –
グローバル変数を宣言し、メソッド内で値を代入します。 –
@AnuradhSはい、私はコードがかなり複雑なので、それを避けようとしていますが、グローバル変数を使用する方法は私にとってはそうです。ありがとう! – SanitLee