2017-05-30 55 views
-2

我在我的項目中創建了一個類。並且該類連接到服務器,並通過調用UIViewController中的send()函數將消息發送到服務器。Swift Event捕捉並知道?

服務器正在接收並通過發回消息作出響應。我的StreamDelegate(連接)獲取事件,我收到消息。現在的問題。通過在用戶界面中按下一個按鈕,發送消息後,我想表現出一個TextView或標籤的響應。但是,我如何從Connection類獲取消息給ViewController?以及如何處理用戶界面。我希望用戶等待,而不是做其他的事情(也許檢查登錄)。

回答

0

我認爲你應該使用負載指示:

let alertController = UIAlertController(title: nil, message: "Loading \n\n", preferredStyle: .alert) 

let spinnerIndicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge) 

spinnerIndicator.center = CGPoint(x: 135.0, y: 65.5) 
spinnerIndicator.color = UIColor.black 
spinnerIndicator.startAnimating() 

alertController.view.addSubview(spinnerIndicator) 
self.present(alertController, animated: false, completion: nil) 

,當你有你的消息發回,只需使用:

alertController.dismiss(animated: true, completion: nil); 

予以駁回。 過程中顯示的時間負載指示,用戶無法點擊或做任何事情。