繁体   English   中英

条形按钮项目未在SWIFT中显示

[英]Bar Button item not showing in SWIFT

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

@IBOutlet弱var songSelectionBar:UIBarButtonItem!

这是我的项目的屏幕截图。 我是新手,所以我知道我正在做一些应该很简单(也许不是)的事情。

下拉菜单应位于选择歌曲的旁边

这是项目中的更多代码。 此函数返回目录的内容。 我的理解是,我应该使用表格视图来显示此函数的输出。 谁能给我指出一个例子或告诉我如何做到这一点? 谢谢

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
                                       }

如果仅声明IBOutlet,而不是将其从IB中拖出,则应摆脱“弱点”。
IB对它的IBOutlet有很强的引用,因此您必须使用弱的IBOutlet。
相反,如果您手动声明IBOutlet,则必须对其进行严格引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM