Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
HomeViewController
class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, SendingBookDataProtocol {
@IBOutlet weak var addBookButton: UIButton!
@IBOutlet var tableView: UITableView!
var gadgets = [BookItem]()
override func viewDidLoad() {
tremendous.viewDidLoad()
tableView?.delegate = self
tableView?.dataSource = self
let nib = UINib(nibName: "BookCell", bundle: nil)
tableView?.register(nib, forCellReuseIdentifier: "BookCell")
}
func sendDataToHomeController(bookEntry merchandise:BookItem) {
gadgets.append(merchandise)
tableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
gadgets.rely
}
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
}
}
}
BookDetailView
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() {
tremendous.viewDidLoad()
bookTitle.textual content = lblName
currentPageDetail.textual content = lblCurrentPage
totalPagesDetail.textual content = lblTotalPages
}
}