我的cellForRow方法中有以下崩溃报告。
这不是我在xCode中运行时可以重现的东西。
viewWillDisappear
我读到有问题的错误与NSNotificationCenter相关联,我需要删除override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NotificationCenter.default.addObserver(self, selector:#selector(checkTimeout), name: NSNotification.Name(rawValue: "appOpened"), object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated);
NotificationCenter.default.removeObserver(self)
}
override func viewWillDisappear(_ animated: Bool)
{
//should I add NotificationCenter.default.removeObserver(self) here and remove it from the other two places above?
if let answers = Helper_EQI_Answer.getAnswers(inspectionID)
{
inspection?.answers = answers;
}
}
中的观察者。
我已经在deinit和viewDidDisappear中删除了我的观察者。如果我将观察者的删除添加到viewWillDisappear中,这应该解决我的问题吗?
此外,如果我将观察者删除添加到viewWillDisappear,我应该在deinit和viewDidDisappear中删除此代码吗?
上一个代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if let item: = insp_Questions?[indexPath.row]{
if 1...12 ~= item.type && answerIDs != nil
{
switch (EQI_QuestionType(rawValue: item.type)!)
{
case .true_false:
if let cell = tableView.dequeueReusableCell(withIdentifier: "IQ_FlipCell") as? IQ_FlipCell
{
cell.table = questionTable;
cell.delegate = self;
cell.qID = answerIDs![indexPath.row];
cell.selectionStyle = .none
//this empty line is 610
if questionNA[indexPath.row]
{
cell.NABox.setImage(#imageLiteral(resourceName: "checkbox_selected"), for: .normal);
cell.questionItem.isHidden = true;
} else {
cell.NABox.setImage(#imageLiteral(resourceName: "checkbox_up"), for: .normal);
cell.questionItem.isHidden = false;
}
let cell2 = cell.formatCell(with: item, for: cell, at: indexPath, qtype: 0)
textHeight[indexPath.row] = cell.questionText.numberOfVisibleLines;
if item.question.characters.count > 40
{
textHeight[indexPath.row] += 1
}
return cell2;
}
}
}
}
return UITableViewCell();
}
CellForRow片段: 我包含了指向第610行的switch语句的情况.EQI_Question类型是枚举。所有案例都在开关中得到满足
<?php if (!empty($this->product->customfieldsSorted['youtube'])) {
$this->position = 'youtube';
echo '<button class="shop_tablinks tab2" onclick="openSpecs(event, \'Specs3\')">';
echo JText::_('Video');
echo '</button>';
} // Product Custom ontop end
?>