gpt4 book ai didi

ios - 在 TableView 中不显示任何数据 - 当没有数据从 api 返回时

转载 作者:可可西里 更新时间:2023-11-01 00:51:32 25 4
gpt4 key购买 nike

我有大约 15 个 Collection View 单元格。当用户单击每个单元格时,相应的单元格数据将显示在下一个屏幕表格 View 中。但是,有些单元格没有任何数据。在那种情况下,我需要在表格中穿鞋查看“无数据”。如何显示??

这是我的代码:

这些是我的 TableView 中的委托(delegate)方法:

 // array to store the value from json
var arrDict = [Businessdata]()



func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}

// number of rows
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.arrDict.count

}


// calling each cell based on tap and users ( premium / non premium )
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{


//let cell:customCell = self.TableViewList.dequeueReusableCellWithIdentifier("cell") as! customCell
let cell:customCell = tableView.dequeueReusableCellWithIdentifier("cell") as! customCell

cell.vendorName.text = arrDict[indexPath.row].BusinessName
cell.vendorAddress.text = arrDict[indexPath.row].Address
cell.VendorRating.rating = arrDict[indexPath.row].Rating!

return cell
}

请帮助我,我必须声明的地方。我是 ios 开发的新手。谢谢!

最佳答案

试试这个:

func numberOfSectionsInTableView(tableView: UITableView) -> Int 
{

var numOfSection: NSInteger = 0

if YourArraydata.count > 0
{

self.tableView.backgroundView = nil
numOfSection = 1


}
else
{

var noDataLabel: UILabel = UILabel(frame: CGRectMake(0, 0, self.tableView.bounds.size.width, self.tableView.bounds.size.height))
noDataLabel.text = "No Data Available"
noDataLabel.textColor = UIColor(red: 22.0/255.0, green: 106.0/255.0, blue: 176.0/255.0, alpha: 1.0)
noDataLabel.textAlignment = NSTextAlignment.Center
self.tableView.backgroundView = noDataLabel

}

return numOfSection
}

enter image description here

关于ios - 在 TableView 中不显示任何数据 - 当没有数据从 api 返回时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909901/

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