У меня есть UIViewController
с UISegmentedControl
, из которого я хотел бы представить UITableViewController
как пирог, когда я нажимаю на segmentedControl
сегменте. Проблема, с которой я сталкиваюсь, - это момент, когда я нажимаю на сегмент, popover начинает загружаться, но сбой при загрузке myPopoverTableViewController. Он падает ватрибуты UITableViewCell являются нулевыми, когда инстанцировании UITableView как пирог
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
, заявив, что атрибуты моего PopoverTableViewCell
: nil
.
Ради простоты я буду ссылаться на мои классы здесь:
myViewController: MyViewController
myPopoverTVController: PopoverTableViewController
myPopoverTVCell: PopoverTableViewCell
В lldb
, я проверил для значений клетки, dataSource
, и кажется, что единственное, что ноль являются атрибуты из myPopoverTVCell
, который я зарегистрироваться в myPopoverTVController's viewWillAppear
с помощью следующей строки:
tableView.register(PopoverTableViewCell.self, forCellReuseIdentifier: "cell")
myPopoverTVController
не подключен через поповер Segue (хотя я пробовал) в myViewController
. Я проверил, что у меня есть PopoverTableViewCell
, указанный в классе для ячейки прототипа myPopoverTVController's
. Я дважды проверил соединения из ячейки с классом PopoverTableViewCell
. Я проверил, что у меня есть идентификатор ячейки таблицы, установленный на cell
на раскадровке.
Вот как я начинаю поповер от myViewController
после Apple's code:
@IBAction func segmentedControlAction(_ sender: UISegmentedControl) {
// instantiate the PopoverTableViewController
let popoverTVC = PopoverTableViewController()
// set variables on it
popoverTVC.selectedSegmentIndex = sender.selectedSegmentIndex
popoverTVC.currentRegion = currentRegion
// disignate presentation style as a popover
popoverTVC.modalPresentationStyle = .popover
present(popoverTVC, animated: true, completion: nil)
let presentationController = UIPopoverPresentationController(presentedViewController: popoverTVC, presenting: self)
presentationController.permittedArrowDirections = .up
presentationController.sourceView = view
presentationController.sourceRect = segmentedControl.frame
}
На myPopoverTVController
, вот что мой cellForRowAt indexPath
выглядит следующим образом:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PopoverTableViewCell
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! PopoverTableViewCell
// Configure the cell...
switch selectedSegmentIndex {
case 0, 1:
cell.areaLabel.text = popoverStringArray[indexPath.row]
case 2:
let countryList = locationManager.countryList
let countryCodes = locationManager.countryCodes
cell.areaLabel?.text = countryList[indexPath.row]
cell.flagLabel?.text = countryCodes[indexPath.row]
default:
break
}
return cell
}
Я проверил переменные, которые устанавливаются при конкретизации на myViewController
, и у всех есть ценности. Это только атрибуты tableViewCell
, которые являются nil
. - lldb
возвращает адрес памяти для ячейки при вводе po cell
. Я установил UITableViews
миллион раз, но я не могу понять эту штуку. Любые предложения re: то, что я делаю неправильно, очень ценится. Я буду уверена, что моя проблема - поразительное глупое упущение с моей стороны. Спасибо за чтение.
У вас есть ячейки с идентификатором повторного использования «клеток» с классом PopoverTableViewCell? Проверяйте идентификатор повторного использования один раз. – Rajat
Да, это была одна из первых вещей, которые я проверил. Я почти уверен, что это связано с созданием popover, поскольку я много раз настраивал TVC. – Adrian
Попробуйте создать экземпляр объекта PopoverTableViewController, как этот «let controller = storyboard.instantiateViewController (withIdentifier:« someViewController ») как! PopoverTableViewController – Rajat