How to enlarge tableView on scroll? - ios

I'm sorry if this is a duplicate. I tried to review similar questions in SO - still doesn't quite make me understand how to deal with this.
I have a tableView, three textViews and a UIButton. When the user scrolls the tableView, the tableView should pushes the textFields and the button out the image and take up more space. When that is done I want to continue scrolling through the cells.
(I want one of the textFields to always remain and still show the title.)
I think I need to put the textViews and button above the tableView inside a tableView header after which I need to set certain constraints between the UIView above the tableView and tableView itself. Then I need to play around with the UIScrollViewDelegate and calculate something.
As you guys can probably tell, I'm relatively new in programming and I believe this i why I don't quite understand the related questions. And as you can probably tell too, why I am pretty damn confused about how to solve my problem!
Here's a photo of the VC:
I wan't the tableView to go and cover the 'AddNewPersonBtn' and the two bottom textView - leaving only the top textView, the navigationBar and the tableView on the screen. --> Until you then scroll down again and the rest will be visible again.
And here goes the code for the VC:
import UIKit
import RealmSwift
class AllPersonsInYourDiary: UIViewController, UITableViewDelegate, UITableViewDataSource {
var diary: Diaries?
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var showingDiaryName: UILabel!
#IBOutlet weak var showingDiaryQuestion: UILabel!
#IBOutlet weak var showingExtraIdentifer: UILabel!
#IBOutlet weak var diaryTheme: UIImageView!
#IBOutlet weak var diaryPhoto: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.tableFooterView = UIView()
self.tableView.tableHeaderView = UIView()
}
override func viewWillAppear(_ animated: Bool) {
tableView.reloadData()
showDiaryIdentifiers()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func createNewPersonButton () {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier:
"PersonViewController") as! PersonViewController
controller.mode = .create
controller.diary = diary
self.navigationController?.pushViewController(controller, animated: true)
}
#IBAction func showEditFunc () {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SettingsVC") as! SettingsVC
controller.diary = diary
self.navigationController?.pushViewController(controller, animated: true)
}
func showDiaryIdentifiers () {
self.showingDiaryName.text = diary?.diaryName
self.showingDiaryQuestion.text = diary?.diaryQuestion
self.showingExtraIdentifer.text = diary?.diaryExtraIdentifier
self.diaryTheme.image = UIImage(data: diary?.diaryTheme ?? Data()) ?? UIImage(named: "Blank")
// self.diaryPhoto.image = UIImage(data: diary?.diaryPhoto ?? Data ()) ?? UIImage(named: "Blank")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return diary!.people.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Person1", for: indexPath) as! PersonCell
let date = DateFormatter.localizedString(from: (diary?.people[indexPath.row].dateCreated)!, dateStyle: .short, timeStyle: .none)
cell.personName.text = diary?.people[indexPath.row].name
cell.personAnswer.text = date
cell.personPhoto.image = UIImage(data: diary?.people[indexPath.row].photo ?? Data()) ?? UIImage(named: "PortaitPhoto")
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier:
"PersonViewController") as! PersonViewController
controller.person = diary?.people[indexPath.row]
controller.diary = diary
controller.mode = .show
self.navigationController?.pushViewController(controller, animated: true)
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let alert = UIAlertController(title: "Are you sure you wish to delete person?", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "No thanks!", style: .cancel)
let action1 = UIAlertAction(title: "Delete!", style: .destructive, handler: { _ in
let realm = try! Realm()
try! realm.write {
guard let person = self.diary?.people[indexPath.row] else {
return
}
self.diary!.people.remove(at: indexPath.row)
realm.delete(person)
}
tableView.deleteRows(at: [indexPath], with: .fade)
})
alert.addAction(action)
alert.addAction(action1)
present(alert, animated: true)
} }
}

Related

Unable to get my "Save" Button to work, my button does nothing when pressed

I'm trying to make a note taking app, however, I'm kinda stuck on how to get my save button to work. Here's what I've got so far:
My Add "Item" View
class AddViewController: UIViewController {
#IBOutlet var addShortDescription: UITextField!
#IBOutlet var addLongDescription: UITextView!
public var completion: ((String, String) -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
addShortDescription.becomeFirstResponder()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Save", style: .done, target: self, action: #selector(didTapSave))
self.title = "Add New Item"
}
#IBAction func didTapSave(_ sender: Any) {
if let text = addShortDescription.text, !text.isEmpty, !addLongDescription.text.isEmpty {
completion?(text, addLongDescription.text)
}
}
}
My Main View
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet var table: UITableView!
var models: [(ShortDescription: String, LongDescription: String)] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
table.delegate = self
table.dataSource = self
self.title = "Inventory"
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return models.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = models[indexPath.row].ShortDescription
cell.detailTextLabel?.text = models[indexPath.row].LongDescription
return cell
}
#IBAction func addNewInventory(){
guard let vc = storyboard?.instantiateViewController(identifier: "add") as? AddViewController else {
return
}
vc.title = "Add New Item"
vc.navigationItem.largeTitleDisplayMode = .never
vc.completion = { addShortDescription, addLongDescription in
self.navigationController?.popToRootViewController(animated: true)
self.models.append((ShortDescription: addShortDescription, LongDescription: addLongDescription))
self.table.isHidden = false
self.table.reloadData()
}
navigationController?.pushViewController(vc, animated: true)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let model = models[indexPath.row]
// Show addLongDescription controller
guard let vc = storyboard?.instantiateViewController(identifier: "inventory") as?
EditViewController else {
return
}
vc.navigationItem.largeTitleDisplayMode = .never
vc.title = "Edit Item"
vc.addShortDescription.text = model.ShortDescription
vc.addLongDescription.text = model.LongDescription
navigationController?.pushViewController(vc, animated: true)
}
}
I have another view where I plan on allowing the user to edit the added items, I'll add that if you think it may be causing some problems.

How pass the value of a selected cell to another ViewController?

Essentially, I have the following UITableViewController that contains custom tableView cells with labels in them. When the cell is selected I would like the value of the cell to be passed to the next view controller where I am using it in an HTTP POST response.
What can be added to didSelectRowAt to pass the value of the selected cell to the view controller presented?
Perhaps as a variable?
The following is my code:
import UIKit
class ScheduledCell: UITableViewCell {
#IBOutlet weak var ETALabel: UILabel!
#IBOutlet weak var cellStructure: UIView!
#IBOutlet weak var scheduledLabel: UILabel!
#IBOutlet weak var testingCell: UILabel!
#IBOutlet weak var pickupLabel: UILabel!
#IBOutlet weak var deliveryLabel: UILabel!
#IBOutlet weak var stopLabel: UILabel!
#IBOutlet weak var topBar: UIView!
}
class ToCustomerTableViewController: UITableViewController, UIGestureRecognizerDelegate {
var typeValue = String()
var driverName = UserDefaults.standard.string(forKey: "name")!
var structure = [AlreadyScheduledStructure]()
override func viewDidLoad() {
super.viewDidLoad()
fetchJSON()
//Disable delay in button tap
self.tableView.delaysContentTouches = false
tableView.tableFooterView = UIView()
}
private func fetchJSON() {
guard let url = URL(string: "https://example.com/example/example"),
let value = driverName.addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed)
else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = "driverName=\(value)".data(using: .utf8)
URLSession.shared.dataTask(with: request) { data, _, error in
guard let data = data else { return }
do {
self.structure = try JSONDecoder().decode([AlreadyScheduledStructure].self,from:data)
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
catch {
print(error)
}
}.resume()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return structure.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "scheduledID", for: indexPath) as! ScheduledCell
let portfolio = structure[indexPath.row]
cell.stopLabel.text = "Stop \(portfolio.stop_sequence)"
cell.testingCell.text = portfolio.customer
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let portfolio = structure[indexPath.row]
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "scheduledDelivery")
print(portfolio.customer)
controller.navigationItem.title = navTitle
navigationController?.pushViewController(controller, animated: true)
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 200.0
}
}
Create public variables for the data which you want to pass to the scheduledDelivery controller.Then set them inside didselect delegate method. Let say if you want to pass portfolio.customer. Declare following public variable on scheduledDelivery controller.
public var portfilio:String?
Then set value to that variable from the didselect method like this,
let portfolio = structure[indexPath.row]
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "scheduledDelivery")
controller.portfilio = portfolio.customer
controller.navigationItem.title = navTitle
navigationController?.pushViewController(controller, animated: true)
add a portfolio variable to your next ViewController
class scheduledDeleivery: UIViewController{
var customer:String? //suposing this is customer type
then in
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let portfolio = structure[indexPath.row]
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "scheduledDelivery") as! shcheduledDeleivery
controller.customer = porfolio.customer //here is the customer you need to pass to next viewcontroller
print(portfolio.customer)
controller.navigationItem.title = navTitle
navigationController?.pushViewController(controller, animated: true)
}
You can store the cell's data as a variable and then in prepare for segue function pass it to the other ViewController. If you call this in prepare for segue it will automatically do it every time you try to access that segue.
var nameOfVar : String = ""
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var secondVC = segue.destination as! YourSecondViewController
secondVC.variable = nameOfVar
}
Hope I've helped :)

How do I lock specific rows in a tableview through in-app purchases?

I have a tableview that requires users to pay in order to access its content. However, the entire tableview is locked. I would like to have, for example, the first two rows unlocked and the third row locked. I also have other tableviews with over 12 rows in them, but just posting this view controller for now. I am feeding in my data through an array, and I already have in-app purchases set up. Here is my current code:
import Foundation
import UIKit
class TrappingVC: UIViewController {
#IBOutlet weak var buildingTableView: UITableView!
#IBOutlet weak var settingsButtonItem: UIBarButtonItem!
var trapping: [CellObject] = []
var segueIdentifiers = ["a", "b"]
//VIEWDIDLOAD
override func viewDidLoad() {
super.viewDidLoad()
//LOAD ARRARYS
trapping = createBuildArray()
buildingTableView.delegate = self
buildingTableView.dataSource = self
self.buildingTableView.rowHeight = 100.0
buildingTableView.tableFooterView = UIView()
//CELL SEPARATORS
buildingTableView.layoutMargins = UIEdgeInsets.zero
buildingTableView.separatorInset = UIEdgeInsets.zero
buildingTableView.separatorColor = UIColor.black
buildingTableView.register(UINib.init(nibName: "TrappingCell", bundle: nil), forCellReuseIdentifier: "TrappingCell")
settingsButtonItem.image = UIImage(named: "Settings")
}
#IBAction func showSettingsClicked(_ sender: Any) {
performSegue(withIdentifier: "showSettings", sender: self)
}
//CREATE ARRAY OF BASIC LESSONS
func createBuildArray() -> [CellObject]{
var tempTrapping: [CellObject] = []
let trapping1 = CellObject(image: #imageLiteral(resourceName: "Yellow"), title: "Below")
let trapping2 = CellObject(image: #imageLiteral(resourceName: "Yellow"), title: "Side")
let trapping3 = CellObject(image: #imageLiteral(resourceName: "Yellow"), title: "Above")
tempTrapping.append(trapping1)
tempTrapping.append(trapping2)
tempTrapping.append(trapping3)
return tempTrapping
}
}
//TABLE
extension TrappingVC: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return trapping.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let trappings = trapping[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "TrappingCell") as! TrappingCell
cell.trappingTitle.text = trappings.title
cell.trappingImage.image = trappings.image
if let purchased = UserDefaults.standard.value(forKey: "payment") as? Bool{
if purchased == true{
cell.lockedImage.isHidden = true
}else{
cell.lockedImage.isHidden = false
}
}else{
cell.lockedImage.isHidden = false
}
cell.layoutIfNeeded()
cell.layoutMargins = UIEdgeInsets.zero
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let purchased = UserDefaults.standard.value(forKey: "payment") as? Bool{
if purchased == true{
performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
}else{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "UnlockContentVC")
self.navigationController?.pushViewController(controller, animated: true)
}
}else{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "UnlockContentVC")
self.navigationController?.pushViewController(controller, animated: true)
}
tableView.deselectRow(at: indexPath, animated: true)
}
}
I fixed it with the following code:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let purchased = UserDefaults.standard.value(forKey: "payment") as? Bool
if indexPath.row < 5 {
performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
}
else if purchased == true {
performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
} else {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "UnlockContentVC")
self.navigationController?.pushViewController(controller, animated: true)
}
tableView.deselectRow(at: indexPath, animated: true)
}

How to instantiate a new view controller programmatically

I have a ViewController with two UIButtons and UIlabels.
In order to make similar ViewController of this, I would like to instantiate a new view controller programmatically
like this.
let vc = storyboard.instantiateViewControllerWithIdentifier("Main")
Then navigate to the view controller like this:
navigationcontroller?.pushViewController(vc, animated: true)
I have set StoryBoard ID as "Main", however I do not know where I can write these codes.
class ViewController: UIViewController, AVAudioPlayerDelegate {
let url1 = Bundle.main.bundleURL.appendingPathComponent("music1.mp3")
let url2 = Bundle.main.bundleURL.appendingPathComponent("music2.mp3")
#IBOutlet weak var label1: UILabel!
#IBOutlet weak var label2: UILabel!
#IBOutlet weak var yourButton1: customButton!
#IBOutlet weak var yourButton2: customButton!
override func viewDidLoad() {
super.viewDidLoad()
label1.text = "Hello1"
label2.text = "Hello2"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func player(url: URL) {
do {
try player = AVAudioPlayer(contentsOf:url)
player.play()
} catch {
print(error)
}
}
#IBAction func pushButton1(sender: UIButton) {
player(url: url1)
}
#IBAction func pushButton2(sender: UIButton) {
player(url: url2)
}
}
tableView
class SecondTableViewController: UITableViewController {
var names = [String]()
var identities = [String]()
override func viewDidLoad() {
names = ["name1","name2","name3","name4"]
identities = ["Main","Main2","Main3","Main4"]
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
let label1 = cell?.viewWithTag(1) as! UILabel
label1.text = "\(names[indexPath.row])"
return cell!
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vcName = identities[indexPath.row]
let ViewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(ViewController!, animated: true)
}
}
You need to set Storyboard ID value for the view controller in storyboard and use it here:
let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "RegistrationController")
navigationcontroller?.pushViewController(vc, animated: true)
Edit:
var urls1 = [String]()
var urls2 = [String]()
override func viewDidLoad() {
names = ["name1","name2","name3","name4"]
identities = ["A","B","C","D"]
urls1 = ["url1","url2" ....]
urls2 = ["url1","url2" ....]
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let url1 = urls1[indexPath.row]
let url2 = urls2[indexPath.row]
//let ViewController = storyboard?.instantiateViewController(withIdentifier: vcName) this is wrong you only have one viewcontroller on storyboard and its storyboard id is fixed.
let viewController: ViewController = storyboard?.instantiateViewController(withIdentifier: "StoryboardID") as! ViewController
viewController.url1 = url1
viewController.url2 = url2
self.navigationController?.pushViewController(ViewController!, animated: true)
}

How to share data of tableViewCell to next viewController without using storyboard in ios with Swift

I am using Xib files in my project for building interface of my app.
I have a tableView in my first viewController from which I want to pass data to next ViewController. I have created a custom cell for my tableView which contains an imageView and two labels.
This is my code
import UIKit
class YASProductListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// registering my custom cell
tableView.registerNib(UINib(nibName: "YASProductListTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell")
let cell : YASProductListTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! YASProductListTableViewCell
cell.productNameLabel.text = prodcutNames[indexPath.row]
cell.productDetailLabel.text = productDetail[indexPath.row]
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return prodcutNames.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 140
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! YASProductListTableViewCell
let destination = YASProductDetaiilViewController(nibName: "YASProductDetaiilViewController", bundle: NSBundle.mainBundle())
destination.productImage = cell.productImageView.image
destination.productTitle = cell.productNameLabel.text!
let productDetails = YASProductDetaiilViewController(nibName: "YASProductDetaiilViewController", bundle: nil) as YASProductDetaiilViewController
navigationController?.navigationBarHidden = false
navigationController?.title = ""
navigationController?.pushViewController(productDetails, animated: true)
}
Now what I want to do is pass the image and labels text to next viewController when user tap on any cell. Here is the code of next ViewController
import UIKit
class YASProductDetaiilViewController: UIViewController {
#IBOutlet weak var productImageView: UIImageView!
#IBOutlet weak var productTitleLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
setupViewControllerUI()
// Do any additional setup after loading the view.
}
// MARK: - UIViewController helper Methods
func setupViewControllerUI(){
productImageView.image = productImage
productTitleLabel.text = productTitle
}
}
As you can see I have tried it didSelectRowAtIndexPath but its not working. Please help! Thanks
You are using right method to share data between viewController. However you have made a mistake. You are creating two instance of your ProductDetailViewController. You need to create only one instance of destination ViewCotroller and then set its properties accordingly you you can simply replace your didSelectRowAtIndexPath method with following
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! YASProductListTableViewCell
let productDetails = YASProductDetaiilViewController(nibName: "YASProductDetaiilViewController", bundle: nil) as YASProductDetaiilViewController
productDetails.productImage = cell.productImageView.image
productDetails.productTitle = cell.productNameLabel.text!
navigationController?.pushViewController(productDetails, animated: true)
}
I hope it will work.
Change your didSelect method like below code,
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! YASProductListTableViewCell
let productDetails = YASProductDetaiilViewController(nibName: "YASProductDetaiilViewController", bundle: nil) as YASProductDetaiilViewController
navigationController?.navigationBarHidden = false
navigationController?.title = ""
productDetails.productImage = cell.productImageView.image
productDetails.productTitle = cell.productNameLabel.text!
navigationController?.pushViewController(productDetails, animated: true)
}
Hope this helps you.
Do as follow might be help you.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! YASProductListTableViewCell
let objYASProductDetaiilViewController = self.storyboard?.instantiateViewControllerWithIdentifier("STRORYBOARD_ID") as? YASProductDetaiilViewController
objYASProductDetaiilViewController.productImage = cell.productImageView.image
objYASProductDetaiilViewController.productTitle = cell.productNameLabel.text!
self.navigationController?.pushViewController(objMedicalDevicesVC!, animated: true)
navigationController?.navigationBarHidden = false
navigationController?.title = ""
navigationController?.pushViewController(objYASProductDetaiilViewController, animated: true)
}
Here You can not assign a image View to image View directly.You need to get a image first then it give to a other view controller image then set it to image to UIImage
import UIKit
class YASProductDetaiilViewController: UIViewController {
#IBOutlet weak var productImageView: UIImage!
#IBOutlet weak var productTitleLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
setupViewControllerUI()
// Do any additional setup after loading the view.
}
// MARK: - UIViewController helper Methods
func setupViewControllerUI(){
productImageView.image = productImage
productTitleLabel.text = productTitle
}
}
create dictionary of all the needed information and the add to array and get using indexpath.row when cell is clicked
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var dicTemp=prodcutNames[indexPath.row] as! NSMutableDictionary
let destination = YASProductDetaiilViewController(nibName: "YASProductDetaiilViewController", bundle: NSBundle.mainBundle())
destination.productImage = prodcutNames.valueForKey("imageObj") //get image object
destination.productTitle = prodcutNames.valueForKey("product_title")//get product title
let productDetails = YASProductDetaiilViewController(nibName: "YASProductDetaiilViewController", bundle: nil) as YASProductDetaiilViewController
navigationController?.navigationBarHidden = false
navigationController?.title = ""
navigationController?.pushViewController(productDetails, animated: true)
}

Resources