这是我在这里发表的第一篇文章,如果我忘记发布一两个细节,请原谅我:)
代码如下:
import UIKit
import Foundation
class MemeTableVC: UIViewController, UITableViewDataSource, UITableViewDelegate, UINavigationControllerDelegate {
@IBOutlet weak var memeTable: UITableView!
var memes : [Meme]!
override func viewWillAppear(_ animated: Bool) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
memes = appDelegate.memes
self.memeTable.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return memes.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MemeCell")!
let memeListItem = memes[(indexPath as NSIndexPath).row]
cell.textLabel?.text = "\(memeListItem.topText!)"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let detailController = self.storyboard!.instantiateViewController(withIdentifier: "SavedMemeVC") as! SavedMemeVC
let meme = memes[(indexPath as NSIndexPath).row]
detailController.memeImage = meme.memedImage
self.navigationController!.pushViewController(detailController, animated: true)
print("something")
}
}
答案 0 :(得分:1)
您应该添加{1}} tableview
delegate