gpt4 book ai didi

ios - UITableViewCell 显示文档文件夹中的错误结果

转载 作者:行者123 更新时间:2023-11-30 14:11:37 25 4
gpt4 key购买 nike

我有 UITableViewController 以及文档文件夹中的文件。我用艺术家的名字命名这些细胞。我有三位艺术家和四首歌。 UITableViewCell 显示具有同一艺术家的两个单元格。我该如何修复它?

enter image description here此代码从文档文件夹导出数据

var mp3Files: Array<String!>!
func exportData() {
var generalURL: [AnyObject]?
var arrayFiles: Array<NSURL!>!
var directory = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)
var urlFromDirectory = directory.first as! NSURL

var file = fileManager.contentsOfDirectoryAtURL(urlFromDirectory, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions.SkipsHiddenFiles, error: nil)!
println("file \(file)")

mp3Files = file.map(){ $0.lastPathComponent }.filter(){ $0.pathExtension == "mp3" }

println("mp3 files \(mp3Files)")
}

并用代码填充UITableViewCell

    var cellStrings: String!
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

var dataForCell = mp3Files[indexPath.row]
var generalURL: NSURL!

var documentFolder = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)

if var urlFromFolder: NSURL = documentFolder.first as? NSURL {
generalURL = urlFromFolder.URLByAppendingPathComponent(dataForCell)
println("general \(generalURL)")
}

var player = AVPlayerItem(URL: generalURL)
var metaData = player.asset.commonMetadata as! [AVMetadataItem]
for item in metaData {
if item.commonKey == "artist" {
nameArtist = item.stringValue
}
}

cell.textLabel?.text = nameArtist
//
cellStrings = cell.textLabel?.text
println("cell strings \(cellStrings)")
// Configure the cell...

return cell
}

最佳答案

 var superArray = [String]()
var filterArray = [String]()
func filter() {
var proString: String!
for proItem in mp3Files {
var proFolder = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask)
var americaURL: NSURL!
if var proURL: NSURL = proFolder.first as? NSURL {
americaURL = proURL.URLByAppendingPathComponent(proItem)
}
var proPlayerItem = AVPlayerItem(URL: americaURL)
var proData = proPlayerItem.asset.commonMetadata as! [AVMetadataItem]
for proFiles in proData {
if proFiles.commonKey == "artist" {
superArray.append(proFiles.stringValue)
}
}
}
filterArray = Array(Set(superArray))
filterArray.sort(){ $0 < $1 }
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1 ?? 0
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return filterArray.count ?? 0
}

var name: String!
var nameArtist: String!


//
var cellStrings: String!
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

nameArtist = filterArray[indexPath.row]

cell.textLabel?.text = nameArtist

return cell
}

关于ios - UITableViewCell 显示文档文件夹中的错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31701582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com