Ios TableView和Detail Segue
我试图使用“performsguewithidentifier”将值从tableview传递到某个细节视图。“详细信息”页面工作正常,但值未正确显示在屏幕上。如果我在tableview第一个选项中单击,则详细信息页面的内容将显示为空白。如果单击第二项,则第一项将加载到详细信息页面 我的tableview代码:Ios TableView和Detail Segue,ios,objective-c,uitableview,tableview,segue,Ios,Objective C,Uitableview,Tableview,Segue,我试图使用“performsguewithidentifier”将值从tableview传递到某个细节视图。“详细信息”页面工作正常,但值未正确显示在屏幕上。如果我在tableview第一个选项中单击,则详细信息页面的内容将显示为空白。如果单击第二项,则第一项将加载到详细信息页面 我的tableview代码: override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let object = objectAtIndexPath(indexPath)
self.titulo = object!.objectForKey("titulo") as! String
self.sub_titulo = object!.objectForKey("sub_titulo") as! String
self.url = object!.objectForKey("url") as! String
self.tipo = object!.objectForKey("tipo") as! Int
//Chama a segue
self.performSegueWithIdentifier("detailSegue", sender: self)
}
//In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let svc = segue.destinationViewController as! DetailViewController
svc.titulo = self.titulo
svc.sub_titulo = self.sub_titulo
svc.url = self.url
svc.tipo = self.tipo
}
My detailview控制器:
import UIKit
class DetailViewController: UIViewController {
@IBOutlet weak var imagemDestaque: UIImageView!
@IBOutlet weak var tituloLabel: UILabel!
@IBOutlet weak var conteudoLabel: UILabel!
var titulo = String()
var sub_titulo = String()
var tipo = Int()
var url = String()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.s
print(self.titulo)
tituloLabel.text = self.titulo
conteudoLabel.text = self.sub_titulo
}
}
按如下方式更改代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//Chama a segue
self.performSegueWithIdentifier("detailSegue", sender: self)
}
//In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let svc = segue.destinationViewController as! DetailViewController
let indexPath = tableView.indexPathForSelectedRow()
let object = objectAtIndexPath(indexPath)
svc.titulo = object!.objectForKey("titulo") as! String
svc.sub_titulo = object!.objectForKey("sub_titulo") as! String
svc.url = object!.objectForKey("url") as! String
svc.tipo = object!.objectForKey("tipo") as! Int
}
我尝试了此代码,但问题是相同的如果我在tableview第一个选项中单击,则详细信息页面的内容将显示为空白。如果我单击第二项,他们会在详细信息页面中加载第一项,而不是正确加载。您是否调试
prepareforsgue
在那里放置断点,然后尝试加载代码