【发布时间】:2015-05-31 10:53:17
【问题描述】:
我知道这个问题已经得到解答,但这并不能解决我的问题。问题是当我通过 segue 传递数据时,它在目标 ViewController 中返回 nil。 假设我在目标 ViewController 中定义了一个 News() 对象和三个字符串对象,我在 Segue 方法中设置了这些对象,但在目标 ViewController 中得到了 nil。
class NewsDetailViewController: UIViewController {
var objNews = News();
var newsTime: String?
var newsDetail: String?
var imageURL: String?
// rest of the class
.
.
}
这是我的segue方法
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Pass the selected object to the new view controller.
if segue.identifier == "SegueNewsDetail" {
var ndVC = NewsDetailViewController();
var indexPath: NSIndexPath = self.tblViewStudent.indexPathForSelectedRow()!
var tempObj = self.news.objectAtIndex(indexPath.row) as News
ndVC.objNews = (self.news.objectAtIndex(indexPath.row) as News)
ndVC.newsTime = tempObj.created_at;
ndVC.newsDetail = tempObj.newsDescription;
ndVC.imageURL = tempObj.imageURL;
println("\(ndVC.newsTime) \(ndVC.newsDetail) \(ndVC.imageURL)")
}
当我尝试在 segue 方法中记录值以检查值是否设置时(这些值设置为所需的值,我的意思是不要在 segue 方法中得到 nil):
println("\(ndVC.newsTime) \(ndVC.newsDetail) \(ndVC.imageURL)")
我尝试了很多选项,但都失败了。 任何人请帮助..
提前致谢
【问题讨论】: