ios – Reassign TableView Cell Variable from one other ViewController

I am engaged on an App the place you’ll be able to observe your studying Progress for Books. I’ve 3 ViewControllers. One is the HomeViewController, the place I’ve a TableView which shows the e-book. Second is the AddBookController, the place you’ll be able to enter some knowledge, press a Button and create a brand new row within the TableView. Third is the BookDetailViewController, which is exhibiting whenever you click on on the chosen row. Right here I’m caught. There’s a button you press and the corresponding TableView Cell ought to replace its web page quantity.

Can you employ Notification Middle for this? There isn’t any Segue from HomeViewController to BookDetailViewController

I have been attempting for hours however cannot work out the best way to do it. I would respect any assist.


class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, SendingBookDataProtocol {

    @IBOutlet weak var addBookButton: UIButton!
    @IBOutlet var tableView: UITableView!
    var gadgets = [BookItem]()

    override func viewDidLoad() {

        tableView?.delegate = self
        tableView?.dataSource = self

        let nib = UINib(nibName: "BookCell", bundle: nil)
        tableView?.register(nib, forCellReuseIdentifier: "BookCell")

    func sendDataToHomeController(bookEntry merchandise:BookItem) {

    func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      let bookDetailVc = self.storyboard?.instantiateViewController(withIdentifier: "BookDetailView") as? BookDetailViewController

        let merchandise = gadgets[indexPath.row]
        let currentPageInt = Float(merchandise.currentPage)!
        let totalPagesInt = Float(merchandise.totalPages)!
        bookDetailVc?.lblName = merchandise.title
        bookDetailVc?.lblCurrentPage = merchandise.currentPage
        bookDetailVc?.lblTotalPages = merchandise.totalPages
          self.navigationController?.pushViewController(bookDetailVc!, animated: true)

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "BookCell", for: indexPath) as! BookCell
        let merchandise = gadgets[indexPath.row]
        cell.bookImage.picture = merchandise.picture
        cell.title.textual content = merchandise.title
        cell.writer.textual content = merchandise.writer
        cell.pageNumbers.textual content = "P. " + merchandise.currentPage + " / " + merchandise.totalPages
        cell.title.textual content = merchandise.title

        return cell

        override func put together(for segue: UIStoryboardSegue, sender: Any?) {
            if segue.identifier == "getBookData" {
                let addBookVC: AddBookController = segue.vacation spot as! AddBookController
                addBookVC.delegate = self


class BookDetailViewController: HomeViewController{

    @IBOutlet weak var bookTitle: UILabel!
    @IBOutlet weak var currentPageDetail: UILabel!
    @IBOutlet weak var totalPagesDetail: UILabel!

    var lblName = String()
    var lblCurrentPage = String()
    var lblTotalPages = String()

 override func viewDidLoad() {

        bookTitle.textual content = lblName
        currentPageDetail.textual content = lblCurrentPage
        totalPagesDetail.textual content = lblTotalPages



See also  Methods to arrange pgSQL for Fluent 4?

Leave a Reply