我的页面上有tableView
,当我按下特定行时,我的应用程序应该使用segue显示另一个页面。然而,当我点击相应的行时它会冻结,然后当我点击不同的行时,segue最终显示出来,这很奇怪。代码曾经为我工作但由于某种原因停止了,我无法识别问题,因为代码是相同的(至少就我所见)。这是一段代码:
func restClient(client: DBRestClient!, loadedFile destPath: String!, contentType: String!, metadata: DBMetadata!){
let title = "This format is incorrect"
let message = "You can only download file that is in .txt format"
let okText = "OK"
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let okayButton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil)
alert.addAction(okayButton)
if contentType.rangeOfString("text") != nil{
print("this is text")
self.performSegueWithIdentifier("segue", sender: nil)
}
else{
print("this is an error")
presentViewController(alert, animated: true, completion: nil)
return;
}
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString
print("The file \(metadata.filename) was downloaded. Content type: \(contentType). The path to it is : \(documentsDirectoryPath)" )
progressBar.hidden = true
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let localFilePath = documentsURL.URLByAppendingPathComponent("Documents")
let checkValidation = NSFileManager.defaultManager()
if (checkValidation.fileExistsAtPath(localFilePath.path!))
{
print("FILE AVAILABLE");
}
else
{
print("FILE NOT AVAILABLE");
}
return
}
didDeselectRowAtIndexPath代码:
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath){
let selectedFile: DBMetadata = dropboxMetadata.contents[indexPath.row] as! DBMetadata
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let localFilePath = (documentsDirectoryPath as NSString).stringByAppendingPathComponent(selectedFile.filename)
print("The file to download is at: \(selectedFile.path)")
print("The documents directory path to download to is : \(documentsDirectoryPath)")
print("The local file should be: \(localFilePath)")
showProgressBar()
dbRestClient.loadFile(selectedFile.path, intoPath: localFilePath as String)
}
下图说明了我点击file.txt行的时间。你可以看到它只是保持灰色而没有任何反应,但在那之后,如果我点击另一个文件,比如enumrec.pdf,它将显示相应的页面。如果有人能指出我在这里做错了什么会很高兴。
答案 0 :(得分:3)
您应该使用didSelectRowAtIndexPath
代替didDeselectRowAtIndexPath
。在使用自动完成时,通常会先提出最新信息,这很容易犯错误。
答案 1 :(得分:2)
看起来你在数据调用之后执行你的seque,这是在另一个线程上(所以你的应用程序可以在你的数据调用运行时继续)。当您更改UI时,您必须在主线程上运行它,否则您可能会遇到类似这样的问题。只需将performSegue代码包装在:
中newpredictions<-predict(results,PimaIndiansDiabetes_Test[,1:8])
您可以在这里阅读线程/背景任务等: