gpt4 book ai didi

ios - 不打印 indexPath.row 处的所有索引

转载 作者:行者123 更新时间:2023-11-30 11:41:44 24 4
gpt4 key购买 nike

我遇到的问题是 eventsList 在索引上有一个数字,我们将使用 27 作为示例,当我运行以下代码时, print (eventLatitudeString) 和 print (eventLongitudeString) 行仅打印一小部分他们,两次。我是新手,请原谅我的困惑。

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let path = Bundle.main.path(forResource: "Agencies", ofType: "plist"),
let agencyNameDict = NSDictionary(contentsOfFile: path) as? [String: String] {
translatedAgencyName = agencyNameDict[eventsList[indexPath.row].agencyId!]
}



let cell = myTableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! ViewControllerTableViewCell

// create dateFormatter with UTC time format
utcDate = eventsList[indexPath.row].dateTime
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
dateFormatter.timeZone = NSTimeZone(name: "UTC")! as TimeZone
let date = dateFormatter.date(from: utcDate!)

// change to a readable time format and change to local time zone
dateFormatter.dateFormat = "MM-dd-yy HH:mm"
dateFormatter.timeZone = NSTimeZone(name: "EST")! as TimeZone
timeStamp = dateFormatter.string(from: date!)

cell.locationLabel.text = eventsList[indexPath.row].location
cell.eventTimeLabel.text = timeStamp
cell.eventTypeLabel.text = eventsList[indexPath.row].agencyEventTypeCode
cell.agencyIdLabel.text = translatedAgencyName
cell.eventTypeDescLabel.text = eventsList[indexPath.row].agencyEventTypeCodeDesc

let numOfEvents = eventsList.count
let stringNumOfEvents = "\(numOfEvents)"
numberOfEvents.text = stringNumOfEvents

eventLatitudeString = eventsList[indexPath.row].latitude!
eventLongitudeString = eventsList[indexPath.row].longitude!

print (eventLatitudeString)
print (eventLongitudeString)

如果有必要,这里就是将项目附加到 eventsList 的地方...

func fetchData(){

print ("entered fetch")

ref?.child("caddata").observe(.childAdded, with: { (snapshot) -> Void in

if let dictionary = snapshot.value as? [String: Any] {
let event = Events()
event.setValuesForKeys(dictionary)

if event.originatingAction == "CadEventNew" {
self.eventsList.insert(event, at: 0)

} else if event.originatingAction == "CadFieldEvent" {
self.eventsList.insert(event, at: 0)

} else if event.originatingAction == "CadEmergencyEvent" {
self.eventsList.insert(event, at: 0)

} else if event.originatingAction == "CadCloseEvent" {
self.cadPacketType = event.originatingAction
self.cadEventNumber = event.agencyEventId
self.queryCloseUIDFromDB()

} else {
// print ("The End")
}
DispatchQueue.main.async {
self.myTableView.reloadData()
}

}
})

}

最佳答案

请确保

func numberOfSections(in tableView: UITableView) -> Int {
print("number of sections numberOfSections : \(tableView)")
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("numberOfRowsInSections tableView : \(tableView)")
return eventsList.count
}

另外请检查所有被调用的索引路径,只需打印indexPath,记住一件事。 cellForRowAt indexPath 仅在单元格显示时调用。如果单元格位于 tableview 滚动的可见内容之外,则不会调用此方法。

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

print("IndexPath - Section:\(indexPath.section) row:\(indexPath.row)")

if let path = Bundle.main.path(forResource: "Agencies", ofType: "plist"),
let agencyNameDict = NSDictionary(contentsOfFile: path) as? [String: String] {

.........................

关于ios - 不打印 indexPath.row 处的所有索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49223779/

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