[英]failed to obtain a cell from its dataSource for swift4.2
下面的代碼有什么問題:
// MARK: - TABLEVIEW DATA SOURCE
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
return weeklyWeather.count
}
func tableView(tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
as! DailyWeatherTableViewCell
let dailyWeather = weeklyWeather[indexPath.row]
if let maxTemp = dailyWeather.maxTemperature {
cell.temperatureLabel.text = "\(maxTemp)"
}
cell.weatherIcon.image = dailyWeather.icon
cell.dayLabel.text = dailyWeather.day
return cell
}
我試圖將UITableViewDataSource和UITableViewDelegate協議添加到ViewController聲明中。
和我的DailyViewController:
class DailyViewController: UIViewController,
CLLocationManagerDelegate {
// MARK: properties
@IBOutlet weak var weatherIcon: UIImageView!
@IBOutlet weak var summaryLabel: UILabel!
@IBOutlet weak var sunriseTimeLabel: UILabel!
@IBOutlet weak var sunsetTimeLabel: UILabel!
@IBOutlet weak var lowTemperatureLabel: UILabel!
@IBOutlet weak var highTemperatureLabel: UILabel!
@IBOutlet weak var precipitationLabel: UILabel!
@IBOutlet weak var humidityLabel: UILabel!
和WeeklyTableViewController:
class WeeklyTableViewController: UITableViewController {
// MARK: - PROPERTIES
@IBOutlet weak var currentTemperatureLabel: UILabel?
@IBOutlet weak var currentWeatherIcon: UIImageView?
@IBOutlet weak var currentPrecipitationLabel: UILabel?
@IBOutlet weak var currentTemperatureRangeLabel: UILabel?
但我無法從其dataSource獲取單元
整個異常是:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'UITableView
(<UITableView: 0x7fcfa7038600; frame = (0 0; 414 896);
clipsToBounds = YES; autoresize = W+H; gestureRecognizers =
<NSArray: 0x600003a31800>; layer = <CALayer: 0x600003476ca0>;
contentOffset: {0, -88}; contentSize: {414, 684};
adjustedContentInset: {88, 0, 34, 0}>) failed to obtain a cell
from its dataSource (<Rainy.WeeklyTableViewController:
0x7fcfa800c200>)'
您可以打印weeklyWeather.count來查看其編號嗎?
您還可以通過在tableView:cellForRowAt方法的開頭設置一個斷點來窺視該單元格。
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.