MBProgressView와 함께 취소 버튼을 사용하려고합니다. 나는 또한 시도MBProgressView를 사용하여 취소 버튼
hud.button.addTarget(hud.progressObject, action: cancelButton(), for: .touchUpInside)
이 일을 " '셀렉터'가 예상 인수 형식에 '()'형태의 값을 변환 할 수 없습니다"오류가 점점 오전 :
hud.button.addTarget(hud.progressObject, action: #selector(cancelButton), for: .touchUpInside)
을 나는 오류 "를 가지고 #selector 인수는 로컬 함수 'cancelButton()'을 참조 할 수 없습니다.
누구든지 나에게 잘못을 설명 할 수 있습니까?
취소 버튼이있는 viewDidLoad에 있어야 또는 내가 다운로드 취소 HUD와 snapshot.progress를 사용할 필요가 있기 때문에 적어도 내가있는 viewDidLoad 안에 무엇에 액세스 할 수있는 방법을 찾을 필요가 : 취소
override func viewDidLoad() {
super.viewDidLoad()
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.orintation = UIInterfaceOrientationMask.allButUpsideDown
if book?.bookPath != book?.bookPath {
print("HERE \(book?.bookPath)")
loadReader(filePaht: (book?.bookPath)!)
} else {
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let strName = book?.id
let filePath = "\(documentsPath)/"+strName!+".pdf"
let fileManager = FileManager.default
if fileManager.fileExists(atPath: filePath) {
loadReader(filePaht: filePath)
return;
}
print("DOWNLOAD #1")
let reference = FIRStorage.storage().reference(forURL: (self.book?.bookURL)!)
let downloadTask = reference.data(withMaxSize: 50 * 1024 * 1024) { (data, error) -> Void in
if (error != nil) {
} else {
if ((try! data?.write(to: URL.init(fileURLWithPath: filePath, isDirectory: false))) != nil) {
self.db.upDate(id: (self.book?.id)!, bookPath: filePath)
self.loadReader(filePaht: filePath)
}
}
}
downloadTask.observe(.resume) { (snapshot) -> Void in
// Download resumed, also fires when the download starts
}
downloadTask.observe(.pause) { (snapshot) -> Void in
// Download paused
}
downloadTask.observe(.progress) { (snapshot) -> Void in
DispatchQueue.global(qos: .default).async(execute: {() -> Void in
self.showHUDWithCancel("Downloading")
DispatchQueue.main.async(execute: {() -> Void in
})
})
self.hud.progressObject = snapshot.progress
}
downloadTask.observe(.success) { (snapshot) -> Void in
// Download completed successfully
print("Download Success")
SwiftLoader.hide()
}
downloadTask.observe(.failure) { (snapshot) -> Void in
//Download failed
print("Download failed")
}
}
}
func showHUDWithCancel(_ aMessage: String) {
self.hud = MBProgressHUD.showAdded(to: self.view, animated: true)
self.hud.mode = MBProgressHUDMode.annularDeterminate
self.hud.label.text = aMessage
self.hud.detailsLabel.text = "Tap to cancel"
let tap = UITapGestureRecognizer(target: self, action: #selector(cancelButton))
self.hud.addGestureRecognizer(tap)
}
func cancelButton() {
self.hud.hide(animated: true)
self.hud.progressObject?.cancel()
print("cancel button is working")
}
이것은을 버튼 기능
func cancelButton() {
MBProgressHUD.hide(for: view, animated: true)
snapshot.progress?.pause()
}
'함수? –
@NiravD 내가 액세스해야하는 문제는 hud = MBProgressHUD.showAdded (to : self.view, animated : true)로 숨겨야합니다. viewdidload에 있지만 viewdidload 외부에있는 cancelButton 함수를 사용할 수없고 동시에 hud에 액세스 할 수 없습니다. – Khallad
viewDidLoad에서 코드를 게시 할 수 있습니까? –