14
のパラメータとして関数を渡す:は、私が期待するように私はiOSの8で、作業以下の機能を持っているスウィフト
func showConfirmBox(msg:String, title:String,
firstBtnStr:String,
secondBtnStr:String,
caller:UIViewController) {
let userPopUp = UIAlertController(title:title,
message:msg, preferredStyle:UIAlertControllerStyle.Alert)
userPopUp.addAction(UIAlertAction(title:firstBtnStr, style:UIAlertActionStyle.Default,
handler:{action in}))
userPopUp.addAction(UIAlertAction(title:secondBtnStr, style:UIAlertActionStyle.Default,
handler:{action in}))
caller.presentViewController(userPopUp, animated: true, completion: nil)
}
私はあることを引数としてメソッドを渡すために、次のようなものを作りたいです
func showConfirmBox(msg:String, title:String,
firstBtnStr:String, firstSelector:Selector,
secondBtnStr:String, secondSelector:Selector,
caller:UIViewController) {
let userPopUp = UIAlertController(title:title,
message:msg, preferredStyle:UIAlertControllerStyle.Alert)
userPopUp.addAction(UIAlertAction(title:firstBtnStr, style:UIAlertActionStyle.Default,
handler:{action in caller.firstSelector()}))
userPopUp.addAction(UIAlertAction(title:secondBtnStr, style:UIAlertActionStyle.Default,
handler:{action in caller.secondSelector()}))
caller.presentViewController(userPopUp, animated: true, completion: nil)
}
はもちろん、私は私が今動作しなかったためにアップしようとしているものをするので、firstSelectorとsecondSelectorで正しいことをやっておりません:1またはボタンの他にタッチしようとしているときに実行。私は私が望むものに対して正しい構文を使用していないと思いますが、私がしたいことをすることは可能です。適切にそれを行う方法の任意のアイデア?
のようなあなたのメソッドを呼び出すことができますか?より具体的な情報を提供してください。 –
私が意味するのは、コンパイラからエラーメッセージが出るということです。それが有用であれば、それらを含めることができます。むしろ、私は2番目の関数の構文が間違っていると思います。 – Michel
私は他の方法(例えばジェネリックを使って)を見つけるために自分で努力していますが、この時点ではまだ成功していません。 – Michel