在表视图中不显示数据 – 当没有数据从api返回时

我有一些15个集合视图单元格。当用户点击每个单元格时,相应的单元格数据将显示在下一个屏幕表格视图中。但是,有些单元格没有任何数据。在这种情况下,我需要在表格中查看“没有数据“。如何显示?

这是我的代码:

这些是我的表视图中的委托方法:

// 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 } 

在此处输入图像描述