Reputation: 157
this is my first post on here, so please forgive me if I forget to post a detail or two:)
Code is below:
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")
}
}
Upvotes: 1
Views: 130
Reputation: 1142
You should add delegate
of tableview
override func viewDidLoad() {
super.viewDidLoad()
memeTable.delegate = self
}
Upvotes: 1