私のアプリケーションでプログレスバーを表示および非表示にするメソッドを定義したいと思います。しかし、私は各ビューコントローラでこれらのローカルメソッドを作成したくありません。どのようにビューをパラメータとして取るグローバルメソッドを定義し、それを使って何かをします。ここでviewcontrollerからアクセス可能な関数を作成するには?
は、私が試したものです:
import Foundation
import MBProgressHUD
public class ShowLoading{
let view = UIView()
func show(){
let loadingNotification = MBProgressHUD.showHUDAddedTo(view, animated: true)
loadingNotification.color = UIColor.blueColor()
loadingNotification.mode = MBProgressHUDMode.Indeterminate
loadingNotification.labelText = MyConstants.LOADING_TEXT
}
func hide(){
MBProgressHUD.hideAllHUDsForView(view, animated: true)
}
}
可能な複製(http://stackoverflow.com/questions/29262540/call-a-function-from-a-view) –
メソッドを静的に定義し、次のようなパラメータを受け入れるようにします。static func test(view:UIView) – Dershowitz123
AppDelegateクラスでメソッドを定義すると、簡単に提示されたView Controllerインスタンスを取得し、そのコントローラでhudを表示できます。ただし、アプリケーションのUIWindowインスタンスでhudを表示することもできます。 –