私のページにはtableView
があり、特定の行を押すと、私のアプリケーションはsegueを使って別のページを表示することになっています。しかし、適切な行をクリックするとフリーズし、別の行をクリックするとsegueが最後に表示されます。これは奇妙です。私のために働いていたコードが何らかの理由で停止しましたが、コードが同一であるため(少なくとも私が見る限り)、問題を特定することはできません。ここでは、コードスニペットである:PerformSegueWithIdentifierが動作しませんSwift
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コード:私はfile.txtを行をクリックしたとき
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)
}
下の写真は示します。ご覧のとおり、グレーのままで何も起こりませんが、その後、別のファイルをクリックすると、enumrec.pdfというと、適切なページが表示されます。誰かが私がここで間違っていることを指摘できれば幸いでしょう。
このスニペットはどこで実行しますか?それはネットワーク操作の完了ブロックにありますか?もしそうなら、あなたはメインスレッドにperformSegueを送る必要があります – Paulw11
@ Paulw11申し訳ありません私はあなたが何を意味しているのか理解していません。 Dropbox APIを使用してフォルダ内のファイルを表示します(つまり、写真に表示されているすべてのファイル)。 – user3395936
このビューコントローラクラスにすべてのコードを投稿できますか? –