//has sent the friend invitation to user //wait user accept the friend invitation dispatch_async(dispatch_get_main_queue(), { () -> Void in // self.view.makeToast(message: "添加人脉邀请已发送") self.view.makeToast(message: "添加人脉邀请已发送", duration: 0.5, position: HRToastPositionDefault) //pop out previous many vc, goto root vc: //[0] <JianDao.MainViewController: 0x7f80db037600> self.navigationController?.popToRootViewControllerAnimated(true) //select the contact vc gMainVC.selectedIndex = 1 }) |
希望延迟一段时间,再去做事情。
swift delay execution
ios – dispatch_after – GCD in swift? – Stack Overflow
ios – Swift performSelector: withObject: afterDelay: – Stack Overflow
objective c – Adding delay between execution of two following lines – Stack Overflow
xcode – How to create a delay in Swift? – Stack Overflow
最后用:
func delayDispatchInMainThread(delayTimeInSec:Double, thingsTodo:()->()) { let dispatchDelayTime = dispatch_time( DISPATCH_TIME_NOW, Int64(delayTimeInSec * Double(NSEC_PER_SEC)) ) dispatch_after(dispatchDelayTime, dispatch_get_main_queue(), thingsTodo) } let deayTimeInSec:Double = 1 self.view.makeToast(message: "添加人脉邀请已发送", duration: deayTimeInSec, position: HRToastPositionCenter) //TODO: add current contact into contact list delayDispatchInMainThread(deayTimeInSec, thingsTodo: self.closeCurrentAndReturnToMain) func closeCurrentAndReturnToMain(){ //do your things } |
即可。
转载请注明:在路上 » [已解决]swift延迟执行代码做事情