UITableViewCell显示文档文件夹中的错误结果
我有UITableViewController
与文件夹中的文件。 我按艺术家名称命名单元格。 我有三个艺术家和四首歌。 UITableViewCell
显示两个具有相同艺术家的单元格。 我该如何解决?
此代码从文档文件夹导出数据
var mp3Files: Array! func exportData() { var generalURL: [AnyObject]? var arrayFiles: Array! 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 }
- search对象的NSArray以匹配任何属性的string
- 创buildiOS应用程序(Xcode)时,如何closures自动图标“胶凝”
- 仅在UITableView中显示可用CellForRow的分隔符
- iOS UIView动画CATransform3DMakeRotation混乱
- 从JSON对UITableViewsortingNSDictionary
- dynamic修改CAKeyframeAnimation的持续时间
- 有没有办法使用worklight 6.2或phonegap混合应用程序从Android和iOS的另一个应用程序启动一个应用程序?
- 通过Cordova config.xml添加条目到iOS .plist文件
- iOS:使用自我和下划线(_)与variables