【发布时间】:2017-05-14 04:42:29
【问题描述】:
这让我很难过。我正在尝试从集合视图单元到表格视图控制器。当我单击一个单元格(特别是单元格内的一个按钮)时,我应该能够转到表格视图控制器并在表格视图控制器的单元格中单击该单元格的详细信息。
在带有集合视图单元格的视图控制器中,我实现了一个 segue。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "details" {
if segue.identifier == "UsersProfile" {
if let indexPath = sender as? IndexPath{
let vc = segue.destination as! UsersProfileViewController
let post = self.posts[indexPath.row] as! [String: AnyObject]
let posted = self.posts[indexPath.row] as! [NSMutableArray: AnyObject]
let username = post["username"] as? String
let userpicuid = post["uid"] as? String
let userpostuid = posted["uid"] as? NSMutableArray
vc.username = username
vc.userpicuid = userpicuid
vc.posts = userpostuid
print(indexPath.row)
}
}}
当我继续时,用户图片和用户名会很好地出现在详细的表格视图中,但它们不会在表格视图单元格中查看。这是我的表格视图控制器代码:
var posts = NSMutableArray()
@IBOutlet var TableView: UITableView!
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UsersCell", for: indexPath) as! UserProfileTableViewCell
//Configure the cell
print(posts[indexPath.row])
let post = self.posts[indexPath.row] as! [String: AnyObject]
cell.Title.text = post["title"] as? String
cell.Author.text = post["Author"] as? String
cell.Price.text = post["Price"] as? String
if let imageName = post["image"] as? String {
let imageRef = FIRStorage.storage().reference().child("images/\(imageName)")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
if error == nil {
}else {
print("Error downloading image:" )
}})}
return cell
}
表格视图单元格中没有显示任何内容。我是 swift 新手,我一直在努力寻找解决方案,但我做不到。
【问题讨论】:
-
无需在
didselectitem内部实现prepareforsegue
标签: swift uitableview firebase-realtime-database uicollectionview