2015-11-04 56 views
1

我在我的項目中創建了一個簡單的酒吧按鈕項目,但它在運行時未顯示。這是我聲明的方式在SWIFT中沒有顯示酒吧按鈕項目

@IBOutlet weak var songSelectionBar:UIBarButtonItem!

這是我的項目的屏幕截圖。我對swift相當陌生,所以我知道我正在做一些應該很簡單(或者不是)的事情。

the drop down menu should be placed next to select a song

下面是該項目更多的代碼。這個函數返回目錄的內容。我的理解是我應該使用tableview來顯示這個函數的輸出。任何人都可以給我一個例子,或告訴我如何做到這一點?謝謝

func getMusicFilesInDirectory() -> [String] {   
    //var wavFiles:[String] 
    // We need just to get the documents folder url 
    let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first! 

    // now lets get the directory contents (including folders) 
    do { 
     let directoryContents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions()) 
     print(directoryContents) 

    } catch let error as NSError { 
     print(error.localizedDescription) 
    } 
    // now filter the directory to extract only Wav Files 

    do { 
     let directoryUrls = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions()) 
     print(directoryUrls) 
     let wavFilesDir = directoryUrls.filter(){ $0.pathExtension! == "wav" }.map{ $0.lastPathComponent! } 
     wavFiles = ["Wav Music Files:\n" + wavFilesDir.description] 
     } catch let error as NSError { 
     print(error.localizedDescription) 
    } 
    return wavFiles 
             } 
+0

是一個工具欄還是標籤欄? –

+0

@ Mr.T我正在嘗試創建一個不存在於swift中的下拉菜單。所以讀完後我被告知使用Bar按鈕。也許我應該使用不同的對象。不確定從一種語言轉到另一種語言時,這些東西會變得混亂。 – Sophman

回答

1

如果你只是聲明IBOutlet,而不是從IB拖出來,你應該擺脫「弱」。
IB對它的IBOutlet有很強的參考性,所以你必須使用它的弱IBOutlets。
相比之下,如果您手動聲明一個IBOutlet,則必須對其強烈引用。

+0

好點。我只是修復它。仍然試圖圍繞如何讓它出現。 – Sophman