JSON 数据在 detailViewController 中返回空单元格?
JSON data is returning empty cell in detailViewController?
我有一个 collectionViewCell(动态),其中包含图像和 labels(从 JSON
加载)。我想要的是,如果我单击任何单元格(包含 image/folders),它应该显示 detailedViewController 及其内容(也来自 JSON
)。
我的 mainViewController 工作正常。显示数据。
在 mainViewController 中我使用了 didSelectItemAtIndexPath 这样的
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
println("USER TAPPED item# \(indexPath.item)")
let subFolderView:SubFolderViewController = self.storyboard?.instantiateViewControllerWithIdentifier("subFolder") as! SubFolderViewController
self.navigationController?.pushViewController(subFolderView, animated: true)
subFolderView.imageSelected = self.Data[indexPath.row].AbsolutePath
subFolderView.imageSelected = self.Data[indexPath.row].Name
subFolderView.imageSelected = self.Data[indexPath.row].Description
但是点击时返回空视图。
在我的 secondViewController 我有
var imageSelected:String!
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell:SubFolderCollectionViewCell? = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as? SubFolderCollectionViewCell
cell?.subFolderDescription.text = self.Data[indexPath.row].Description
cell?.subFolderName.text = self.Data[indexPath.row].Name
let picUrl = self.Data[indexPath.row].AbsolutePath
let url = NSURL(string: picUrl)
if(url != nil) {
let data = NSData(contentsOfURL : url!)
if(data != nil) {
cell?.subImage?.image = UIImage(data: data!)
}
}
return cell!
}
请任何人指导我进一步......我是 iOS 开发的新手并且更喜欢 swift!!!!!!!
在我的 storyBoadrd 中 viewControllers 包含
View,
Tableview,
TableViewCell,
ContentView,
collectionView,
collectionViewCell.
inside that imageView and labels to display the data
感谢任何帮助,
如果您需要更多代码,请告诉我......
检查你的代码..
您使用 didDeselectItemAtIndexPath 而不是 didSelectItemAtIndexPath 方法..
这是不同的表视图委托方法。更改此设置,如果有任何问题请告诉我。
我有一个 collectionViewCell(动态),其中包含图像和 labels(从 JSON
加载)。我想要的是,如果我单击任何单元格(包含 image/folders),它应该显示 detailedViewController 及其内容(也来自 JSON
)。
我的 mainViewController 工作正常。显示数据。
在 mainViewController 中我使用了 didSelectItemAtIndexPath 这样的
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
println("USER TAPPED item# \(indexPath.item)")
let subFolderView:SubFolderViewController = self.storyboard?.instantiateViewControllerWithIdentifier("subFolder") as! SubFolderViewController
self.navigationController?.pushViewController(subFolderView, animated: true)
subFolderView.imageSelected = self.Data[indexPath.row].AbsolutePath
subFolderView.imageSelected = self.Data[indexPath.row].Name
subFolderView.imageSelected = self.Data[indexPath.row].Description
但是点击时返回空视图。
在我的 secondViewController 我有
var imageSelected:String!
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell:SubFolderCollectionViewCell? = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as? SubFolderCollectionViewCell
cell?.subFolderDescription.text = self.Data[indexPath.row].Description
cell?.subFolderName.text = self.Data[indexPath.row].Name
let picUrl = self.Data[indexPath.row].AbsolutePath
let url = NSURL(string: picUrl)
if(url != nil) {
let data = NSData(contentsOfURL : url!)
if(data != nil) {
cell?.subImage?.image = UIImage(data: data!)
}
}
return cell!
}
请任何人指导我进一步......我是 iOS 开发的新手并且更喜欢 swift!!!!!!!
在我的 storyBoadrd 中 viewControllers 包含
View,
Tableview,
TableViewCell,
ContentView,
collectionView,
collectionViewCell.
inside that imageView and labels to display the data
感谢任何帮助, 如果您需要更多代码,请告诉我......
检查你的代码..
您使用 didDeselectItemAtIndexPath 而不是 didSelectItemAtIndexPath 方法..
这是不同的表视图委托方法。更改此设置,如果有任何问题请告诉我。