Good evening, I have 3 screens in my app to buy passwords, the last one has a tableView powered by the passwords purchased by the user on a previous screen. He must choose a password and it appears in the summary of his request on the next screen in a tableView, if the user wants to buy another password, he can click "next password" and return to the screen of passwords and choose another to be added the one that was chosen previously, but how do you get the information added after choosing the new passwords?
The flow looks like this:
Categories screen: The user chooses which category and goes to the password screen Password screen: The user chooses the password and goes to the summary screen Summary screen: The tableView is fed with the chosen password and if the user wants to buy another, return to the categories screen.
Class where passwords are chosen:
import UIKit
class ComprarSenhaViewController {
static let sharedInstance = ComprarSenhaViewController()
var senhasSelecionadas = Array<String>()
var senhaAtual = Senha()
@IBAction func fecharPedido(sender: AnyObject) {
SenhaController.sharedInstance.senha = self.senhaAtual
senhasSelecionadas.append("\(senhaAtual.id)")
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let novoNavigation = storyBoard.instantiateViewControllerWithIdentifier("ResumoViewController")
self.navigationController?.pushViewController(novoNavigation, animated: true)
}
}
Class where the summary of the chosen passwords is shown:
import UIKit
class ResumoViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
static let sharedInstance = ResumoViewController()
var senhasSelecionadas = Array<String>()
@IBOutlet weak var tableView: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return senhasSelecionadas.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let row = indexPath.row
let idSenha = senhasSelecionadas[row]
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: nil)
cell.textLabel!.text = idSenha
return cell
}
func carregarResumoSenhas(){
ComprarSenhaViewController.sharedInstance.senhasSelecionadas = self.senhasSelecionadas
let idsenha = SenhaController.sharedInstance.senha.id
senhasSelecionadas.append("\(idsenha)")
tableView.reloadData()
}
@IBAction func proximaSenha(sender: AnyObject) {
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let novoNavigation = storyBoard.instantiateViewControllerWithIdentifier("CategoriaViewController")
self.navigationController?.pushViewController(novoNavigation, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
carregarResumoSenhas()
}