Receiver has no segue with identifier 'contact_segue' - ios

I have a problem that the self.performSegueWithIdentifier("contact_segue", sender: self) do not work and complain that Receiver has no segue with identifier 'contact_segue' even i have the identifier. I have used the SWReveal framework to build the left-side sliding menu which is work with table view(class: slidingMenuController). After I clicked the cell to call function changeView of MainNavigationController to do changing views.
import UIKit
class MainNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(animated: Bool){
super.viewDidAppear(false)
self.performSegueWithIdentifier("Home", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if segue.identifier == "Contact_se" {
}
}
func changeView(){
self.performSegueWithIdentifier("contact_segue", sender: self)
}
}
The changeView which is called by an a left-side sliding menu (class: slidingMenuController) in a tablecell:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedItemMenu = arrayOfSlider[indexPath.row]
let mainNav = MainNavigationController()
mainNav.changeView()
}

Just add this code self.performSegueWithIdentifier("contact_segue", sender: self) on your didSelectRowAtIndexPath? I believe there's no need for the MainNavigationController here.

Related

viewDidLoad() load twice when passing data with Navigation Controller - SWIFT

I'm new to swift development. I'm trying to pass data from one UiViewController to Another UIViewController with NavigationController. I was able to pass the data, but for some reason, it loads the viewDidLoad() twice on the second UIViewController. Below is my code.
ViewController
class ViewController: UIViewController {
var option = ""
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// Dine In Btn
#IBAction func dineinBtn(_ sender: Any) {
self.option = "Dine In"
performSegue(withIdentifier: "dinein", sender: self)
}
// Take Out Btn
#IBAction func takeoutBtn(_ sender: Any) {
self.option = "Take Out"
performSegue(withIdentifier: "takeout", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vc = segue.destination as! QualityViewController
vc.option = self.option
}
#IBAction func unwindToVC1(segue:UIStoryboardSegue) { }
}
QualityViewController
class QualityViewController: UIViewController {
var option = ""
override func viewDidLoad() {
super.viewDidLoad()
option += option
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
The reason may be that you hook buttons dineinBtn and takeoutBtn as the segue source , so the IB segue is triggered plus this
performSegue(withIdentifier: "takeout", sender: self)
Another reason may be that you copied the buttons in IB so each one is hooked to 2 IBActions in code

How to bring UIImageView to foreground upon tapping a tableViewCell?

currently thumbnails are being shown in UITableViewCell and upon tapping a cell, I want the image to be shown in foreground with a cross/X button on right top to dismiss the image and show tableView. I have the following code in didSelectRow:
let hoverImage = UIImageView()
hoverImage.image = UIImage(named: "splashpt")
hoverImage.contentMode = .scaleAspectFit
self.view.addSubview(hoverImage)
hoverImage.center = self.view.center
hoverImage.layer.zPosition = 5
self.view.bringSubview(toFront: hoverImage)
Still the image doesn't show up. The computation is hitting this section of the code because I'm able to debug and step through this part of the code. But nothing shows up on screen. I'm using the zPosition AND bringSubview(toFront:) and neither of the seem to work for my requirement. Any help would be greatly appreciated. Thank you.
This is a Demo table view.On tapping the table view cells a view is poped up with close button. And on pressing the close button the pop up view is closed.
import UIKit
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
cell.textLabel?.text = "Happy"
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Cell\(indexPath.row) is selected")
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let popoverVC = storyBoard.instantiateViewControllerWithIdentifier("PopViewController") as! PopViewController
popoverVC.delegate = parentViewController as? InfoViewDelegate
let nav = UINavigationController(rootViewController: popoverVC)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover
nav.navigationBar.hidden = true
self.presentViewController(nav, animated: true)
{
}
popoverVC.passingViewController = self
}
}
This is a PopUpViewController:
import UIKit
protocol InfoViewDelegate: class
{
func infoViewClicked(tag: Int)
}
class PopViewController :UIViewController
{
#IBOutlet weak var btnClose: UIButton!
var delegate = InfoViewDelegate?()
var passingViewController: UIViewController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(animated: Bool) {
}
override func viewDidDisappear(animated: Bool) {
self.presentingViewController?.dismissViewControllerAnimated(true
, completion: {
})
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
#IBAction func btnClicked(sender: UIButton) {
if(sender == self.btnClose)
{
self.delegate?.infoViewClicked(1)
self.presentingViewController?.dismissViewControllerAnimated(true
, completion: {
})
}
}
}

Unwind segue not unwinding

I'm trying to create a simple unwind segue but apparently I've made a mistake somewhere. The save button I would like to unwind reacts to pressing but doesn't unwind to the table view. Thanks in advance I appreciate it.
import UIKit
class NoteTableViewController: UITableViewController {
var notes = [Note]()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
return cell
}
//ACTION
#IBAction func unwindToNoteList(sender: UIStoryboardSegue) {
if let sourceViewController = sender.source as? ViewController, let noteTaken = sourceViewController.noteTaken {
// Add a new meal.
let newIndexPath = IndexPath(row: notes.count, section: 0)
notes.append(noteTaken)
tableView.insertRows(at: [newIndexPath], with: .automatic)
}
}
}
and my view controller
import UIKit
import os.log
class ViewController: UIViewController, UITextFieldDelegate {
#IBOutlet weak var typeField: UITextField!
#IBOutlet weak var textDisplay: UILabel!
#IBOutlet weak var saveButton: UIBarButtonItem!
var noteTaken: Note?
func textFieldDidEndEditing(_ textField: UITextField) {
textDisplay.text = typeField.text
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// Hide the keyboard.
typeField.resignFirstResponder()
return true
}
override func viewDidLoad() {
super.viewDidLoad()
typeField.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
//NAV
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
// Configure the destination view controller only when the save button is pressed.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
os_log("The save button was not pressed, cancelling", log: OSLog.default, type: .debug)
return
}
let note = typeField.text ?? ""
// Set the meal to be passed to MealTableViewController after the unwind segue.
noteTaken = Note(note: note)
}
#IBAction func cancelButton(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
This is how I create my unwind segues:
Write the code for the unwind segue in the first View Controller:
#IBAction func unwindSegue(Segue: UIStoryboardSegue) {
// Run code when the view loads up
}
Create the segue in main.storyboard:
Give the segue an identifier:
then call it in code:
#IBAction func UnwindButton(_ sender: UIButton) {
performSegue(withIdentifier: "UnwindSegue", sender: UIButton())
}
Hope this helps!!!

Next VC is not showing

I have a segue going from the first VC clubSelectionViewController to the one shown below clubSummaryViewController, but I have to click back 2 times to get the next VC to show. What am I doing wrong?
import Foundation
import UIKit
class clubSelectionViewController: UIViewController, UITableViewDelegate {
var clubsForSelection = [clubObject]()
var clubForClubSummaryView = [clubObject]()
#IBAction func selectDanceClubs(sender: AnyObject) {
clubForClubSummaryView = clubDataFilter.removeStripClubsFrom(clubsForSelection)
self.performSegueWithIdentifier("ClubSummary", sender: self)
}
#IBAction func selectStripClubs(sender: AnyObject) {
clubForClubSummaryView = clubDataFilter.removeDanceClubsFrom(clubsForSelection)
self.performSegueWithIdentifier("ClubSummary", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
// everytime screen loads it removes information to give blank screen it removes all clubs in array
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ClubSummary" {
let summaryView = segue.destinationViewController as! clubSummaryViewController
summaryView.clubDetails = [clubObject]()
summaryView.clubDetails = self.clubForClubSummaryView
}
}
}
Second VC
import UIKit
class clubSummaryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var clubDetails = [clubObject]()
var selectedClub = clubObject()
#IBOutlet var clubSummaryTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
//Declare Delegate, Load TableView
clubSummaryTableView.delegate = self
//clubSummaryTableView.dataSource = self
clubSummaryTableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: TableViewDelegate
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.clubDetails.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.clubSummaryTableView.dequeueReusableCellWithIdentifier("SummaryCell")! as? clubSummaryCell
cell?.clubName.text = clubDetails[indexPath.row].clubName
cell?.clubAddress.text = clubDetails[indexPath.row].clubAddress
//TODO: insert image
cell?.clubPhoto.image = clubDetails[indexPath.row].clubImage.image
return cell!
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.selectedClub = self.clubDetails[indexPath.row]
self.performSegueWithIdentifier("ClubDetails", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ClubDetails"{
let clubDetailsView = segue.destinationViewController as? clubInfoViewController
clubDetailsView?.clubForDetails = self.selectedClub
}
}
}
I think the problem in the:
#IBAction func selectDanceClubs(sender: AnyObject) {
clubForClubSummaryView = clubDataFilter.removeStripClubsFrom(clubsForSelection)
self.performSegueWithIdentifier("ClubSummary", sender: self)
}
#IBAction func selectStripClubs(sender: AnyObject) {
clubForClubSummaryView = clubDataFilter.removeDanceClubsFrom(clubsForSelection)
self.performSegueWithIdentifier("ClubSummary", sender: self)
}
I not sure why you want these two func have the same SegueWithIdentifier
The reason might be that you have attached the segue from the button itself.
That means when you click on button the segue from the button is getting called, and since you have action of the button also, the segue is called again from the action method.
Means, the same segue is called twice.

prepareForSegue is not called after performSegueWithIdentifier

I'm new to iOS development. There are many duplicated questions (Sorry). But I could not solve this problem.
prepareForSegue is not called after calling performSegueWithIdentifier.
The show segue identifier is named as 'segue1'.
Ctrl-Dragged from ViewController to DetailViewController.
Am I missing something?
ViewController.swift:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func buttonTapped(sender: AnyObject) {
print("ViewController - buttonTapped()")
performSegueWithIdentifier("segue1", sender: self)
}
override func performSegueWithIdentifier(identifier: String, sender: AnyObject?) {
print("ViewController - performSegueWithIdentifier(): \(identifier)")
}
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
print("ViewController - shouldPerformSegueWithIdentifier()")
return true
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
print("ViewController - prepareForSegue(): \(segue.identifier!)")
}
}
DetailViewController.swift:
class DetailViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("DetailViewController - viewDidLoad()")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Here is a screenshot of storyboard.
Output (after the button is tapped)
ViewController - buttonTapped()
ViewController - performSegueWithIdentifier(): segue1
You're not calling super - add the following to send the message to the parent class (which will in turn fire off the segue)
super.performSegueWithIdentifier(identifier, sender: sender)

Resources