Different back path after segue in swift in IOS
I am trying to segue from VC1 to VC3 which is really easy. Once I am in VC3, I want back button takes back user to VC2. Here is how Storyboard is setup I1 tab1 of a tabcontroller there is only one tableview(VC1). Tab2 has a tableview(VC2) which segues to a UIView(VC3). Now from tab1(VC1) user segues to VC3 but the back path I need to be VC2 in tab2 . I can easily make tab2 selected after segue from VC1 to VC3 but the back button still takes user to VC1.
Let me know if it is not cleat. Thank you
See also questions close to this topic
-
Swift: SIGABRT error when Performing Segue in an SKScene
In the game I am making, I perform a segue from the view controller with my SKScene to the view controller with a UIView when you die. When I die, I make an action to make a fading up alpha of red over the scene. As soon as that is done, I want it to segue to the main menu. I am using the NotificationCenter to trigger the segue from a SKScene. I used a sequence SKAction to perform the segue as soon as the alpha is done scaling up. When I run this, the alpha scales up, then the screen stays the same, not changing ViewControllers. Once I close the app on my phone, I get a SIGABRT error on the line of code performSegue(), listed below.
EDIT: The error in the console is: Assertion failed: (*shader), function xglCompileShader, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Jet/Jet-2.20/Jet/xgl_utils.mm, line 24.
GameViewController:
override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.doaSegue), name: NSNotification.Name(rawValue: "doaSegue"), object: nil) //I kept out all of the code for setting up the scene } @objc func doaSegue(){ performSegue(withIdentifier: "show", sender: self) //The error occurs on this line self.view.removeFromSuperview() self.view = nil }
Gamescene:
To see if it was happening because of the SKAction, I tried it without a SKAction(Code # 2), and the ViewController loaded, but no buttons I clicked in the view worked. After a while the SIGABRT error appeared on the same line.
Code # 1:
let Action1 = SKAction.fadeAlpha(to: 0.75, duration: 5) let Action2 = SKAction.run { print("segue") NotificationCenter.default.post(name: NSNotification.Name(rawValue: "doaSegue"), object: nil) } shape.run(SKAction.sequence([Action1, Action2]))
Code # 2:
// let Action2 = SKAction.run { print("segue") NotificationCenter.default.post(name: NSNotification.Name(rawValue: "doaSegue"), object: nil) // } // shape.run(SKAction.sequence([Action1, Action2]))
What do I do to stop getting this error. I made sure all of the segue was connected and the identifier was the same as in the code. What else would be making this error keep coming up.
I have an image of my storyboard if needed but I don't have enough reputation to post it.
-
Attempt to present UINavigationController on non-existent UINavigationController
I have this error right now:
Warning: Attempt to present <UINavigationController: 0x10d80b800> on <UINavigationController: 0x109891a00> whose view is not in the window hierarchy!
I've seen this before and usually it has to do with
viewDidLoad
versus another place where trying to present, but that isn't the case here.My flow:
LoginViewController (NOT A UINavigationController):
self.performSegue(withIdentifier: "GoToMainVC", sender: nil) override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let identifier = segue.identifier { if identifier == "GoToMainVC" { segue.destination.transitioningDelegate = self segue.destination.modalPresentationStyle = .custom } } }
ProfileViewController (which is a ViewController in a UINavigationController):
self.presentingViewController?.dismiss(animated: true)
Before, I've also had
self.navigationController?.dismiss(animated: true)
for ProfileViewController, but it shouldn't matter.When my application goes through the segue the first time, everything is fine and the UINavigationController is
<UINavigationController: 0x10d81a000>
.After I go through the dismiss and try to segue again, I get the warning above, where
<UINavigationController: 0x10d81a000>
is trying to be presented on<UINavigationController: 0x109891a00>
. I have no idea where the second UINavigationController comes from, as LoginViewController is not a UINavigationController.Totally stumped here.
Update: I fixed my bug by explicitly using
self.presentViewController
instead of the segue, but I'm leaving this here... because it is extremely odd to me and I'd like to know why this would happen. -
Has no segue with identifier 'searchSegue' through xib file's class
I am using a segue(
searchSegue
) to connect my search screen (SearchViewController
) to the search result page (PhotoStreamViewController
).SearchViewController
is a collection view. Every collection view cell has a design in Xib file. (Xib file's class isSearchCategoryRowCell
)Currently, when I triggered
searchSegue
throughSearchViewController
it works fine. But whenever I trigger the same segue throughSearchCategoryRowCell
, I am gettingHas no segue with identifier 'searchSegue'
SearchViewController.swift
class SearchViewController: UIViewController,UISearchBarDelegate,UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{ ... func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { searchRedirect(keyword: searchBar.text!) } func searchRedirect(keyword:String) { performSegue(withIdentifier: "searchSegue", sender:self) PhotoStreamViewController.searchString = keyword navigationController?.setNavigationBarHidden(false, animated: true) } ... }
SearchCategoryRowCell.swift
class SearchCategoryRowCell: UICollectionViewCell { //the method below is triggered by a click action @objc func searchRedirection(_ sender:UIButton) { print("we") print(subCategoryArray[sender.tag].name) let searchViewcontroller = SearchViewController(nibName: "SearchViewController", bundle: nil) searchViewcontroller.searchRedirect(keyword: "otherSearchKeyword") } ... }
-
why my back button is not triggered in the navigation bar stack show segue?
I have 3 VC in here. from the blue one, the user can go either to green or the red one based on some logic.
if the user go from blue to red one, the Back button in the red VC can be used. but if the user go from blue to green, the back button in the green VC can't be used, the user can't go back to the blue VC from greenVC, the problem is only in the greenVC
the video / .gif is in here : http://g.recordit.co/yxSiEd6ji7.gif
the trigger in the blueVC is this code
if needSpeaker { performSegue(withIdentifier: "goToStep5", sender: nil) } else { performSegue(withIdentifier: "goToStep6", sender: nil) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) if segue.identifier == "goToStep5" { let createEventStep5VC = segue.destination as! CreateEventStep5VC createEventStep5VC.newEvent = newEvent } else if segue.identifier == "goToStep6" { let createEventStep6VC = segue.destination as! CreateEventStep6VC createEventStep6VC.newEvent = newEvent } }
and here is the code in the greenVC :
import UIKit class CreateEventStep5VC: UIViewController { @IBOutlet weak var speakerNameLabel: UILabel! @IBOutlet weak var questionTitleLabel: UILabel! @IBOutlet weak var speakerNameTextField: UITextField! var newEvent : [String:Any]! override func viewDidLoad() { super.viewDidLoad() print("step 5") print(newEvent) // initial value speakerNameLabel.text = "" // to make the cursor directly to the textfield when the user open the VC speakerNameTextField.becomeFirstResponder() setQuestionTitle() } @IBAction func nextStepButtonDidPressed(_ sender: Any) { guard let speakerName = speakerNameLabel.text, !speakerName.isEmpty, speakerName != " " else { showAlert(alertTitle: "Mohon Maaf", alertMessage: "Anda harus mengisi nama pematerinya terlebih dahulu.", actionTitle: "Kembali") return } newEvent["speaker"] = speakerName performSegue(withIdentifier: "goToStep6", sender: nil) } // to remove keyboard / cursor if we touch other area override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { self.view.endEditing(false) } } extension CreateEventStep5VC { func setQuestionTitle() { let eventTypes = newEvent["eventType"] as! [EventType] if eventTypes.contains(.ceramah) { questionTitleLabel.text = "Siapa Nama Penceramahnya?" } } } extension CreateEventStep5VC { // MARK : Navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "goToStep6" { let createEventStep6VC = segue.destination as! CreateEventStep6VC createEventStep6VC.newEvent = newEvent navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) } } } extension CreateEventStep5VC : UITextFieldDelegate { // to make live update to UILabel func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let text = textField.text ?? "" speakerNameLabel.text = (text as NSString).replacingCharacters(in: range, with: string) return true } }
what went wrong in here?
-
didSelectRowAt - performSegue indexPath.row to VCs with a different design
I have recently started Xcode and I following one example I did a 'didSelectRowAt' to go from my decided image to the View I want. That's good and all, but now I want to go to Different storyboards and not use my recycled View. I have been pounding this for a couple of days and I really can't seem to figure out how.
This is my VC.swift
class CategoriesVC: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var categoryTable: UITableView! override func viewDidLoad() { super.viewDidLoad() categoryTable.dataSource = self categoryTable.delegate = self } } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let category = DataService.instance.getCategories()[indexPath.row] performSegue(withIdentifier: "ProductsVC", sender: category) performSegue(withIdentifier: kitListIdentifier, sender: category) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let productsVC = segue.destination as? ProductsVC { let barBtn = UIBarButtonItem() barBtn.title = "" navigationItem.backBarButtonItem = barBtn assert(sender as? Category != nil) productsVC.initProducts(category: sender as! Category) } }
}
And this is my storyboard.
Aas you see I want to go to KitList based on the image position I choose from the first VC. In this case, position 0.
Could you give me some help?
Thanks
-
Segue to a view controller embedded with a tab and navigation controller
Hello so basically i'm trying to segue from 1 to 2 and show that screen when the button is clicked. What is happening is that the tab controller is not shown but the navigation is when it segued back to view controller 2. I'm not sure if this should be done programmatically or through the storyboard but I tried searching for a solution online and I haven't seen anybody explain this broadly.
-
IPA upload error
I updated my app for ios 11 using Xcode 9 beta 5.(Objective C app)
The app is running(with Xcode 8.3 as well as Xcode 9 beta) without any error even on the device.
Today, I have created a build using XCode 8.3 to upload on test-flight, Which is giving below error on uploading to iTunes.
ERROR ITMS-90534: "Invalid Toolchain. New apps and app updates must be built with the public (GM) versions of Xcode 6 or later, macOS, and iOS SDK or later. Don't submit apps built with beta software including beta macOS builds."
Note - I used Xcode 8.3 to archive and upload build not Xcode 9 beta
Please suggest any solution to fix this error.
- In Xcode 8.3 some swift class files are in red colour
-
Xcode 9 : Command failed due to signal: Abort trap: 6
I am not able to build in xcode 9. It says Command failed due to signal: Abort trap: 6. I have tried solutions mentioned in stackoverflow, but none of them worked. As its mentioned, overriding description var gives this error. This is done in third party frameworks like SwiftyJson, RealmSwift on which I dont have control to change.
I have both Objc and swift files in the project. It gives
MergeSwiftModule
issue for the following,1. While reading from 'targetname' 2. While deserializing 'NMHTTPResponseSerializer' (ClassDecl #55) in 'targetname'
Due to this error I am not able to build project in Xcode 9 and later. Please help.
-
Application screen sequence in iOS app
In the application I can go from screen A to B to C. Also I can go from screen A to E and also I can go from screen C to E.
I want to know the entry point from where Controller E is presented.
PS : application is storyboard less and can’t post code due to confidentiality.
App is in Swift 3. Looking for some suggestions.
-
Make bold and normal text in a UILabel Swift 3.2
I just updated Xcode, before I used Swift 3.1 and now I use 3.2
Before updated the following code can work pretty good but since updated and now use Swift 3.2, the following code doesn't change any labelText.
@IBOutlet weak var conditionsLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() normalText = "By signing up, you agree to our " boldText = "Terms " normalText2 = "& " politique = "Privacy Policy." var attributedString = NSMutableAttributedString(string: normalText) var attributedString2 = NSMutableAttributedString(string: normalText2) var attrs = [NSFontAttributeName : UIFont.boldSystemFont(ofSize: 10)] var boldString = NSMutableAttributedString(string: boldText, attributes: attrs) var boldString2 = NSMutableAttributedString(string: politique, attributes: attrs) attributedString.append(boldString) attributedString.append(attributedString2) attributedString.append(boldString2) conditionsLabel.attributedText = attributedString }
Then, I tried to use an extension but same issue can't work too:
extension NSMutableAttributedString { @discardableResult func bold(_ text:String) -> NSMutableAttributedString { let attrs:[String:AnyObject] = [NSFontAttributeName: UIFont(name: "AvenirNext-Medium", size: 10)!] let boldString = NSMutableAttributedString(string: text, attributes:attrs) self.append(boldString) return self } @discardableResult func normal(_ text:String)->NSMutableAttributedString { let normal = NSAttributedString(string: text) self.append(normal) return self } } // And in viewDidLoad() method I use this extension like this but can't work override func viewDidLoad() { super.viewDidLoad() let formattedString = NSMutableAttributedString() formattedString .normal("By signing up, you agree to our ") .bold("Terms ") .normal("& ") .bold("Privacy Policy.") conditionsLabel.attributedText = formattedString }
EDIT :
When I used Swift 3.1 Xcode 8.3 (You can see (sorry for French) normal and bold text in the same UILabel)
Then since I updated Xcode to version 9 and Swift 3.2 the same code doesn't work anymore:
Someone have an idea what's wrong with my code in Swift 3.2 ?