gpt4 book ai didi

ios - 我的 UITableView 中没有显示任何数据

转载 作者:搜寻专家 更新时间:2023-11-01 07:23:27 24 4
gpt4 key购买 nike

我的 songName 的 IBOutlet 设置正确,但由于某些原因

import UIKit

class QueueController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

let testUser = Profile.init(username: "test", followers: [], following: [])
let songOne = Song.init(name: "S1", UWR: testUser.username, genre: "rock", artist: "s1")
var moreSongs = [Song]()
moreSongs = [Song(name: "gah", UWR: testUser.username, genre: "gahh", artist: "GAH")]
Queue.createQueue("2321x", creator: testUser, firstSong: songOne, additionalSongs: moreSongs)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
}


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Queue.theQueue!.count
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
if let feed = Queue.theQueue {
return feed.count
} else {
return 0
}
}

func songIndex(cellIndex: Int) -> Int {
return tableView.numberOfSections - cellIndex - 1
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let song = Queue.theQueue![songIndex(indexPath.section)]
let cell = tableView.dequeueReusableCellWithIdentifier("queueCell", forIndexPath: indexPath) as! QueueCell
//cell.textLabel?.text = song.name this doesnt work also
cell.songName.text = "asdad"

return cell
}

}

对于我的 Queue 类:

import UIKit

class Queue {
let creator:Profile!
let planetID:String!
let beginningSong: Song!
var feed:Array<Song>?
static var theQueue:Array<Song>?

init (id:String!, creator:Profile!, firstSong:Song!) {
self.planetID = id
self.creator = creator
self.beginningSong = firstSong
}

func addSong (song: Song) {
feed?.append(song)
}

static func createQueue (id:String!, creator:Profile!, firstSong:Song!, additionalSongs: [Song]) {
let temp = Queue(id: id, creator: creator, firstSong: firstSong)

for song in additionalSongs {
temp.addSong(song)
}

self.theQueue = temp.feed
}
}

歌曲类:

import UIKit

class Song {
let name:String!
let userWhoRequested:String!
let genre: String?
let artist: String?

init (name:String!, UWR:String!, genre:String?, artist:String?) {
self.name = name
self.userWhoRequested = UWR
self.genre = genre
self.artist = artist
}
}


class QueueCell: UITableViewCell {
@IBOutlet weak var songName:UILabel!
@IBOutlet weak var userPicture:UIImageView!
@IBOutlet weak var isCurrent:UIImageView!
}

表格 View 显示正确,但我的 Controller 中没有显示任何数据,我不确定为什么。重用小区标识符也是正确的。 viewDidLoad() 中的数据也在我的 app delegate 的 func application 中。

谢谢!

最佳答案

您的问题在于您的 CreateQueue 方法中的 feed,它从未被初始化

并改变

var feed:Array<Song>?

var feed  = [Song]()

关于ios - 我的 UITableView 中没有显示任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37530624/

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