条形按钮项目未在SWIFT显示

时间:2015-11-04 15:07:03

标签: ios swift uiview xcode7

我在项目中创建了一个简单的Bar按钮项,但是当我运行它时它没有显示。这是我宣布它的方式

@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
                                       }

1 个答案:

答案 0 :(得分:1)

如果您只是声明IBOutlet,而不是从IB中拖出它,那么您应该摆脱“弱”。
IB强烈提及它的IBOutlet,所以你必须使用它的IBOutlets弱。
相比之下,如果手动声明IBOutlet,则必须对其进行强引用。

相关问题