Cercando di elaborare un paio di scene nella mia app, non riesco a far funzionare TableViews come dovrebbero.Errori con le viste della tabella statica
sto facendo un impostazioni come tableView in cui l'utente sceglie tra due possibili impostazioni. Ogni opzione porta a new tableView in cui l'utente deve selezionare una delle opzioni disponibili. Una volta che l'utente ne ha scelto uno, l'etichetta nella prima scena mostrerà il valore scelto (che è memorizzato anche come NSUserDefaults). Quindi, se non sbaglio, ciò potrebbe essere ottenuto con 3 tabelle statiche. Il seguente codice è come Im cercando di farlo:
impostazioni iniziali visualizzare regolatore:
class SettingsVC2: UITableViewController{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0{
let cell = tableView.dequeueReusableCellWithIdentifier("office_cell", forIndexPath: indexPath)
cell.textLabel?.text = "Select your office"
return cell
}
else {
let cell = tableView.dequeueReusableCellWithIdentifier("dept_cell", forIndexPath: indexPath)
cell.textLabel?.text = "Select your department"
return cell
}
Una delle tableViews impostazioni:
class SettingsDepartmentTVC: UITableViewController{
let departamentos: [String] = ["Sales", "Pre-Sales", "General Administration", "Customer Service", "Profesional Services", "Regionales"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return departamentos.count
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("department_cell", forIndexPath: indexPath)
cell.textLabel?.text = self.departamentos[indexPath.row]
return cell
}
}
credo che tutte le origini dati e delegati hanno ragione agganciati e UIKit viene importato anche se non viene mostrato.
Erros Im ottenendo: fallimento
asserzione in - [UITableView dequeueReusableCellWithIdentifier: forIndexPath:]
terminazione app a causa di eccezione non identificata 'NSInternalInconsistencyException', la ragione: 'in grado di annullare l'accodamento una cella con identificatore office_cell - deve registrare un pennino o una classe per l'identificatore o collegare una cella prototipo in uno storyboard
questo è il metodo in cui provo a popolare il tableView:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("CommentsRowTVC", forIndexPath: indexPath) as! CommentsRowTVC
let single_comment = self.AOS[indexPath.row]
cell.titulo_comentario?.text = single_comment.titulo_comment
cell.cuerpo_comentario?.text = single_comment.cuerpo_comment
cell.fecha_comentario?.text = single_comment.fecha_comment
return cell
}
class CommentsRowTVC: UITableViewCell {
@IBOutlet weak var titulo_comentario: UILabel!
@IBOutlet weak var cuerpo_comentario: UILabel!
@IBOutlet weak var fecha_comentario: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
Ecco l'ispettore connessioni per l'UIViewController in cui la tabella è:
E questo per UIViewCellController:
errori a questo punto:
UIView tableView: numberOfRowsInSection: selettore non riconosciuto inviato ad esempio
terminazione app causa eccezione non identificata NSInvalidArgumentException, motivo: [UIView tableView: numberOfRowsInSection:] : selettore non riconosciuto inviato all'istanza
è possibile aggiungere uno storyboard screenshot? – adolfosrs
hai aggiunto l'indentificatore allo storyboard? – adolfosrs
@PabloDuque dovresti impostare un punto di interruzione e provare a passare attraverso il tuo codice, vedere dove si interrompe e riportare –