0
I need you to click on one of the positions of array, the same goes for a specific screen. didSelectRowAtIndexPath method shows black screen and not the screen it should. Follow the code I made until then:
import Uikit
class Viewcontroller: Uiviewcontroller , Uitableviewdatasource, Uitableviewdelegate{
@IBOutlet weak var tableView: UITableView!
var frutas = ["Macã", "Laranja"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
self.title = "Agua"
//self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.frutas.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
let gesture = UILongPressGestureRecognizer(target: self, action: "showAlerta:")
cell.addGestureRecognizer(gesture)
let linha = frutas[indexPath.row]
cell.textLabel?.text = "\(linha)"
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var viewController: UIViewController
if indexPath.row == 0 {
viewController = DetalheViewController()
navigationController?.pushViewController(viewController , animated: true)
}
if indexPath.row == 1 {
viewController = DetalhesDois()
navigationController?.pushViewController(viewController , animated: true)
}
}
func showAlerta(sender: UILongPressGestureRecognizer){
if sender.state == UIGestureRecognizerState.Began {
var alerta = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.Alert)
let show = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default,handler:nil)
alerta.addAction(show)
presentViewController(alerta,animated:true,completion:nil)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "detalhe" {
let destino = segue.destinationViewController as! DetalheViewController
}
if segue.identifier == "detalhedois" {
let destino = segue.destinationViewController as! DetalhesDois
}
}
override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
<#code#>
}
}
This answer here is exactly what you need. See if it is according to what you need.
– Paulo Rodrigues
Partially solved because when I click on one of the cells, a black screen appears. println() works
– Faro
You can update your question with your new attempt so we can better identify the error?
– Paulo Rodrigues
I was able to solve it another way, how do I share this code with the solution for others to see?
– Faro
You can answer your own question and after 2 days you can mark it as the correct ;)
– Paulo Rodrigues