Blank labels after data passing in Swift 4?












-1















I am currently trying to pass data from my table view controller to a second view controller but my labels and image are appearing as blank in the second view controller.



This is my main event view controller:



class EventsTableViewController: PFQueryTableViewController {


override func queryForTable() -> PFQuery<PFObject> {
let query = PFQuery(className: "Events")
//query.order(byAscending: "location")
query.order(byAscending: "date")
return query
}

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Upcoming Events"
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "MasterToDetail" {
let detailVC = segue.destination as! DetailViewController
detailVC.myEventCell = sender as? EventCell
}
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EventCell

cell.dateLabel.text = object?.object(forKey: "date") as? String
cell.locationLabel.text = object?.object(forKey: "location") as? String
cell.nameLabel.text = object?.object(forKey: "name") as? String

let imageFile = object?.object(forKey: "image") as? PFFile

cell.eventImage.image = UIImage(named: "download")

cell.eventImage.file = imageFile
cell.eventImage.loadInBackground()

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "MasterToDetail", sender: EventCell())

}

@IBAction func reloadTable(_ sender: Any) {

self.loadObjects()
}

@IBAction func onSignOutTapped(_ sender: Any) {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
performSegue(withIdentifier: "signOutSegue", sender: nil)
} catch {
print (error)
}

}

}


and my second view controller:



class DetailViewController: UIViewController {


@IBOutlet weak var detailImageView: UIImageView!
@IBOutlet weak var detailNameLabel: UILabel!
@IBOutlet weak var detailDescriptionLabel: UILabel!
@IBOutlet weak var detailLocationLabel: UILabel!

var myEventCell: EventCell?

override func viewDidLoad() {
super.viewDidLoad()

setUI()
}
func setUI () {
detailNameLabel.text = myEventCell?.nameLabel.text
detailImageView.image = myEventCell?.eventImage.image
detailLocationLabel.text = myEventCell?.locationLabel.text
}

}









share|improve this question




















  • 1





    Please don't pass a cell (the view). Don't do that. Pass the object of the data source (the model).

    – vadian
    Nov 21 '18 at 21:54


















-1















I am currently trying to pass data from my table view controller to a second view controller but my labels and image are appearing as blank in the second view controller.



This is my main event view controller:



class EventsTableViewController: PFQueryTableViewController {


override func queryForTable() -> PFQuery<PFObject> {
let query = PFQuery(className: "Events")
//query.order(byAscending: "location")
query.order(byAscending: "date")
return query
}

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Upcoming Events"
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "MasterToDetail" {
let detailVC = segue.destination as! DetailViewController
detailVC.myEventCell = sender as? EventCell
}
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EventCell

cell.dateLabel.text = object?.object(forKey: "date") as? String
cell.locationLabel.text = object?.object(forKey: "location") as? String
cell.nameLabel.text = object?.object(forKey: "name") as? String

let imageFile = object?.object(forKey: "image") as? PFFile

cell.eventImage.image = UIImage(named: "download")

cell.eventImage.file = imageFile
cell.eventImage.loadInBackground()

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "MasterToDetail", sender: EventCell())

}

@IBAction func reloadTable(_ sender: Any) {

self.loadObjects()
}

@IBAction func onSignOutTapped(_ sender: Any) {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
performSegue(withIdentifier: "signOutSegue", sender: nil)
} catch {
print (error)
}

}

}


and my second view controller:



class DetailViewController: UIViewController {


@IBOutlet weak var detailImageView: UIImageView!
@IBOutlet weak var detailNameLabel: UILabel!
@IBOutlet weak var detailDescriptionLabel: UILabel!
@IBOutlet weak var detailLocationLabel: UILabel!

var myEventCell: EventCell?

override func viewDidLoad() {
super.viewDidLoad()

setUI()
}
func setUI () {
detailNameLabel.text = myEventCell?.nameLabel.text
detailImageView.image = myEventCell?.eventImage.image
detailLocationLabel.text = myEventCell?.locationLabel.text
}

}









share|improve this question




















  • 1





    Please don't pass a cell (the view). Don't do that. Pass the object of the data source (the model).

    – vadian
    Nov 21 '18 at 21:54
















-1












-1








-1








I am currently trying to pass data from my table view controller to a second view controller but my labels and image are appearing as blank in the second view controller.



This is my main event view controller:



class EventsTableViewController: PFQueryTableViewController {


override func queryForTable() -> PFQuery<PFObject> {
let query = PFQuery(className: "Events")
//query.order(byAscending: "location")
query.order(byAscending: "date")
return query
}

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Upcoming Events"
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "MasterToDetail" {
let detailVC = segue.destination as! DetailViewController
detailVC.myEventCell = sender as? EventCell
}
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EventCell

cell.dateLabel.text = object?.object(forKey: "date") as? String
cell.locationLabel.text = object?.object(forKey: "location") as? String
cell.nameLabel.text = object?.object(forKey: "name") as? String

let imageFile = object?.object(forKey: "image") as? PFFile

cell.eventImage.image = UIImage(named: "download")

cell.eventImage.file = imageFile
cell.eventImage.loadInBackground()

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "MasterToDetail", sender: EventCell())

}

@IBAction func reloadTable(_ sender: Any) {

self.loadObjects()
}

@IBAction func onSignOutTapped(_ sender: Any) {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
performSegue(withIdentifier: "signOutSegue", sender: nil)
} catch {
print (error)
}

}

}


and my second view controller:



class DetailViewController: UIViewController {


@IBOutlet weak var detailImageView: UIImageView!
@IBOutlet weak var detailNameLabel: UILabel!
@IBOutlet weak var detailDescriptionLabel: UILabel!
@IBOutlet weak var detailLocationLabel: UILabel!

var myEventCell: EventCell?

override func viewDidLoad() {
super.viewDidLoad()

setUI()
}
func setUI () {
detailNameLabel.text = myEventCell?.nameLabel.text
detailImageView.image = myEventCell?.eventImage.image
detailLocationLabel.text = myEventCell?.locationLabel.text
}

}









share|improve this question
















I am currently trying to pass data from my table view controller to a second view controller but my labels and image are appearing as blank in the second view controller.



This is my main event view controller:



class EventsTableViewController: PFQueryTableViewController {


override func queryForTable() -> PFQuery<PFObject> {
let query = PFQuery(className: "Events")
//query.order(byAscending: "location")
query.order(byAscending: "date")
return query
}

override func viewDidLoad() {
super.viewDidLoad()

self.title = "Upcoming Events"
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == "MasterToDetail" {
let detailVC = segue.destination as! DetailViewController
detailVC.myEventCell = sender as? EventCell
}
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! EventCell

cell.dateLabel.text = object?.object(forKey: "date") as? String
cell.locationLabel.text = object?.object(forKey: "location") as? String
cell.nameLabel.text = object?.object(forKey: "name") as? String

let imageFile = object?.object(forKey: "image") as? PFFile

cell.eventImage.image = UIImage(named: "download")

cell.eventImage.file = imageFile
cell.eventImage.loadInBackground()

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "MasterToDetail", sender: EventCell())

}

@IBAction func reloadTable(_ sender: Any) {

self.loadObjects()
}

@IBAction func onSignOutTapped(_ sender: Any) {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
performSegue(withIdentifier: "signOutSegue", sender: nil)
} catch {
print (error)
}

}

}


and my second view controller:



class DetailViewController: UIViewController {


@IBOutlet weak var detailImageView: UIImageView!
@IBOutlet weak var detailNameLabel: UILabel!
@IBOutlet weak var detailDescriptionLabel: UILabel!
@IBOutlet weak var detailLocationLabel: UILabel!

var myEventCell: EventCell?

override func viewDidLoad() {
super.viewDidLoad()

setUI()
}
func setUI () {
detailNameLabel.text = myEventCell?.nameLabel.text
detailImageView.image = myEventCell?.eventImage.image
detailLocationLabel.text = myEventCell?.locationLabel.text
}

}






swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 21:52









vadian

149k14160181




149k14160181










asked Nov 21 '18 at 21:45









Alejandro CarbajalAlejandro Carbajal

1




1








  • 1





    Please don't pass a cell (the view). Don't do that. Pass the object of the data source (the model).

    – vadian
    Nov 21 '18 at 21:54
















  • 1





    Please don't pass a cell (the view). Don't do that. Pass the object of the data source (the model).

    – vadian
    Nov 21 '18 at 21:54










1




1





Please don't pass a cell (the view). Don't do that. Pass the object of the data source (the model).

– vadian
Nov 21 '18 at 21:54







Please don't pass a cell (the view). Don't do that. Pass the object of the data source (the model).

– vadian
Nov 21 '18 at 21:54














1 Answer
1






active

oldest

votes


















0














As you send an empty cell here



performSegue(withIdentifier: "MasterToDetail", sender: EventCell())


You need



let cell = tableView.cellForRow(at:indexPath)
performSegue(withIdentifier: "MasterToDetail", sender:cell)





share|improve this answer
























  • still not working, still getting blank space on the labels

    – Alejandro Carbajal
    Nov 23 '18 at 14:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420908%2fblank-labels-after-data-passing-in-swift-4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As you send an empty cell here



performSegue(withIdentifier: "MasterToDetail", sender: EventCell())


You need



let cell = tableView.cellForRow(at:indexPath)
performSegue(withIdentifier: "MasterToDetail", sender:cell)





share|improve this answer
























  • still not working, still getting blank space on the labels

    – Alejandro Carbajal
    Nov 23 '18 at 14:18
















0














As you send an empty cell here



performSegue(withIdentifier: "MasterToDetail", sender: EventCell())


You need



let cell = tableView.cellForRow(at:indexPath)
performSegue(withIdentifier: "MasterToDetail", sender:cell)





share|improve this answer
























  • still not working, still getting blank space on the labels

    – Alejandro Carbajal
    Nov 23 '18 at 14:18














0












0








0







As you send an empty cell here



performSegue(withIdentifier: "MasterToDetail", sender: EventCell())


You need



let cell = tableView.cellForRow(at:indexPath)
performSegue(withIdentifier: "MasterToDetail", sender:cell)





share|improve this answer













As you send an empty cell here



performSegue(withIdentifier: "MasterToDetail", sender: EventCell())


You need



let cell = tableView.cellForRow(at:indexPath)
performSegue(withIdentifier: "MasterToDetail", sender:cell)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 21:53









Sh_KhanSh_Khan

43.3k51328




43.3k51328













  • still not working, still getting blank space on the labels

    – Alejandro Carbajal
    Nov 23 '18 at 14:18



















  • still not working, still getting blank space on the labels

    – Alejandro Carbajal
    Nov 23 '18 at 14:18

















still not working, still getting blank space on the labels

– Alejandro Carbajal
Nov 23 '18 at 14:18





still not working, still getting blank space on the labels

– Alejandro Carbajal
Nov 23 '18 at 14:18




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420908%2fblank-labels-after-data-passing-in-swift-4%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

ts Property 'filter' does not exist on type '{}'

mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window