gpt4 book ai didi

ios - TableView 填充行,但不填充内容

转载 作者:行者123 更新时间:2023-11-28 11:00:31 25 4
gpt4 key购买 nike

我目前有一个 tableView,其中填充了来自 firebase 数据库的内容。我能够打印出要填充到单元格中的特定信息,并且可以滚动填充数据的适当长度来指示实际填充单元格。我不确定为什么它会访问信息并填充单元格,但不将数据插入单元格?

表格 View :

import UIKit
import FirebaseAuth
import FirebaseStorage

class Articles: UITableViewController {

var vcType:String = "Home"
//var valueTopass = [[String:String]]()
var rooms = [Room]()
var articleCell = ArticlesCell()

@IBOutlet weak var menuButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()

if self.vcType == "Home"
{
self.rooms += ArticlesManager.sharedClient.rooms
}
else
{
if let obj = ArticlesManager.sharedClient.catRooms[self.vcType.lowercased()] //as? [Room]
{
self.rooms += obj
}
}
self.tableView.reloadData()

ArticlesManager.sharedClient.blockValueChangeInRoomArray = {
newRoom in
if self.vcType == "Home"
{
self.rooms.append(newRoom)
self.rooms.sort(by: {
if $0.created_Date == nil
{
return false
}
if $1.created_Date == nil
{
return true
}

return $0.created_Date.compare($1.created_Date) == ComparisonResult.orderedDescending
})

}
else
{
if self.vcType.lowercased() == newRoom.category
{
self.rooms.append(newRoom)

self.rooms.sort(by: {
if $0.created_Date == nil
{
return false
}
if $1.created_Date == nil
{
return true
}

return $0.created_Date.compare($1.created_Date) == ComparisonResult.orderedDescending
})

self.tableView.reloadData()

}
}
}

}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rooms.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

if (indexPath as NSIndexPath).row == 0 {
let cell2 = tableView.dequeueReusableCell(withIdentifier: "featured", for: indexPath) as! featuredCell
let room = rooms[(indexPath as NSIndexPath).row]
cell2.configureCell(room)
self.tableView.reloadData()
return cell2

} else {

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ArticlesCell
let room = rooms[(indexPath as NSIndexPath).row]
cell.configureCell(room)
self.tableView.reloadData()
return cell

}
}
}

文章管理器:

import UIKit

class ArticlesManager: NSObject {

static let sharedClient = ArticlesManager()

var dateFormater:DateFormatter{
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd HH:mm:ss a z"
return df
}

var roomsitems = ["Home", "News", "Features", "Opinion", "Sports", "Entertainment", "Editor"]

var rooms = [Room]()
var catRooms = [String:[Room]]()

var blockValueChangeInRoomArray:((Room) -> ())!

func fetchData()
{
Data.dataService.fetchData {
(room) in

self.rooms.append(room)

self.rooms.sort(by: {
if $0.created_Date == nil
{
return false
}
if $1.created_Date == nil
{
return true
}

return $0.created_Date.compare($1.created_Date) == ComparisonResult.orderedDescending
})

if let obj = self.catRooms[room.category] //as? [Room]
{
var objRooms = obj
objRooms.append(room)

objRooms.sort(by: {
if $0.created_Date == nil
{
return false
}
if $1.created_Date == nil
{
return true
}

return $0.created_Date.compare($1.created_Date) == ComparisonResult.orderedDescending })

self.catRooms[room.category] = objRooms
}
else
{
self.catRooms[room.category] = [room]
}

if self.blockValueChangeInRoomArray != nil
{
self.blockValueChangeInRoomArray(room)
}
}
}

}

数据服务:

import UIKit

class ArticlesManager: NSObject {

static let sharedClient = ArticlesManager()

var dateFormater:DateFormatter{
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd HH:mm:ss a z"
return df
}

var roomsitems = ["Home", "News", "Features", "Opinion", "Sports", "Entertainment", "Editor"]

var rooms = [Room]()
var catRooms = [String:[Room]]()

var blockValueChangeInRoomArray:((Room) -> ())!

func fetchData()
{
Data.dataService.fetchData {
(room) in

self.rooms.append(room)

self.rooms.sort(by: {
if $0.created_Date == nil
{
return false
}
if $1.created_Date == nil
{
return true
}

return $0.created_Date.compare($1.created_Date) == ComparisonResult.orderedDescending
})

if let obj = self.catRooms[room.category] //as? [Room]
{
var objRooms = obj
objRooms.append(room)

objRooms.sort(by: {
if $0.created_Date == nil
{
return false
}
if $1.created_Date == nil
{
return true
}

return $0.created_Date.compare($1.created_Date) == ComparisonResult.orderedDescending })

self.catRooms[room.category] = objRooms
}
else
{
self.catRooms[room.category] = [room]
}

if self.blockValueChangeInRoomArray != nil
{
self.blockValueChangeInRoomArray(room)
}
}
}

}

最佳答案

cellForRowAt indexPath 方法中删除这行代码:

self.tableView.reloadData()

这是在不给它机会配置单元格显示数据的情况下连续重新加载表。

关于ios - TableView 填充行,但不填充内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40858113/

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