How to segue to View Controller from skview - ios

As simple as this question may seem, I just couldn't figure it out. To the overflow community, I am using sprite kit to create a simple game, However when you lose the game I want to programmatically segue back to another viewController (basically the home screen). from The game scene I do not get access to "performSegueWithIdentifier" I've seen a couple answers that relate to this topic however non of them are in swift ... Any solutions?
links of related questions include : Link1
Thank You

I think you are misunderstanding SKViews. SKViews are just like a normal UIViews, they take place within a normal ViewController. You will therefore need to segue from the ViewController which is presenting your SKView.
I have the same issue in a game I have created (Ninja-Shooter). In my game, whenever I want to segue back the home screen I pass a value to NSUserDefaults.standardUserDefaults(). Then in my ViewController I am constantly listening for any change in that value, if the value does change, then I perform a segue.
Hope this helps!

I have discovered that using NSNotification Center Can in fact derive the results I was looking for. If any one in the future needs detailed code I will edit to provide that

Related

Programmatically transitioning between two UIViewControllers (Xcode 9, Swift 4)

The app I am currently working on requires that I do not use ANY storyboards. Therefore I need to do everything programmatically. One thing I seem to be struggling with is switching between two UIViewControllers.
The issue is that every time I call the self.present() method; it creates a brand new instance of the class I would like to show. So when I go into Xcode's visual debugger, I see over 15 different views that are all stacked and are merely instantiations of one another. Ex: View1, View2, View1, View2, View1, View2, View1... This constant repetition of the views is significantly hurting the performance of my app. So my question:
Is there a way that I can switch between my two UIViewControllers without constantly creating a new instance of each one?
Again, I am doing all of this with ALL storyboards DELETED. So the solution I necessary needs to be implemented using ONLY code.
I think you should create main ViewController.
if you keep your two instance view controller, create two controller in mainViewController. Then keep that in main viewController.
And push view controller you want to present in navigation of main view controller
if you want to change second view controller pop navigation controller and push another, or just push other controller.
if you want keep your instance view controller i think it's best option for you
I think that it is really important to realize the fact that the view controller will show up multiple times in the debugger because that is something that can throw off the performance of the app. I really like the way you mention that in your comment. This is one of the main differences that can outstand you from another programmer in the same field. One of the most easiest and simple ways to fix this problem would be using the self.dismiss() method. Another way to dismiss this view controller would be to use a navigation controller to fix this problem. A navigation controller will push the main view controller out of the way and it will not create multiple instances of it. This will be the most efficient as it doesn't require a lot of code and a mere initialization of the UINavigationController class implemented in the UIKit. This is one of the most important tools and resources that you must make use of while coding in xcode and developing your skills in the swift ios field. Since this problem is not one of the most common to find on the internet, it is very beneficial for you to post it on this forum page and will really be helpful for some other programmers unaware of such methods and ways to code. One of the questions that I have for you is the fact that you don't want to use storyboards. Why don't you want to use storyboards and only make it proGrAMitcally? This is one of the very questions that manages to astound me. The storyboard is an implementation that makes it very easy for xcode and swift users to work around the tedious work that has to be done while working in the coding aspect. It only takes a few lines of code and you can get a seGu done very easily. The switch is very easily done and you can find this method on some youtube channels. For this type of work, I recommend VigneshSriniswami Patel and ShaniLakshmiVishnuJiSwami, these content creators will help guide you to becoming an xcode master.
Hope I helped!

XCode Table View vs Button for Menu Solution w/ Different ViewController Destinations

I swear I tried to find an answer to this question but can't seem to lick this issue.
I have a table view that I would like to take the user to 4 different viewcontrollers as each destination viewcontroller from the menu needs very different functionality/layout. However, at present I can only go to one view controller. If I simply put in buttons instead of the table view I can accomplish this but this doesn't seem like best practice and I enjoy some of the clean/tightness of the table view. Also, I do not need to pass anything from the parent viewcontroller.
I'm new, if my newb question wasn't obvious enough. If there is a tutorial/page/resource you can point me to that'd be greatly appreciated by myself and the non-profit I'm trying to do this for :)
Thanks for your time and consideration!
I figured it out. In case someone else has this problem and has stumbled onto my question before seeing it answered elsewhere. A newb like myself didn't know enough about segues. You'll need background on creating segues in storyboard from the parent view controller to the children with unique segue IDs and then take care of the rest in the .m file of the parent. Also be careful about assigning the delegate of your table view as this was another silly oversight of mine.
Here's the link I found most helpful.
Can I use multiple segues with one UITableViewDelegate?

Advise on Custom Segue XCODE

I'm interested in replicating the transition features in the picture below.
I have noticed this being used in multiple apps but am not sure where to start.
The transition literally pushes the current screen away in a direction and is followed by the requested screen. In the picture below, the paper plan button is pressed to initiate this transition
Does anyone know how to create this custom segue or does anyone know of any projects on Github that demonstrate this?
Thanks in advance!
its not a segue you would use. you would use the childViewControllers property of UIViewController to add left and right view controllers than do some animation tricks and gesture recognizers to get it how you want it to look. There are tons of tutorials online just look them up if you don't want to come up with one from scratch.

UIPageViewController with docking/pinning functionality

I've been using UIPageViewController with transitionStyle UIPageViewControllerTransitionStyleScroll in order to be able to easily move between views in my app.
I'm looking for a bit more functionality that I won't get from the UIPageViewController so I'm looking to make my own solution - perhaps still a subclass of UIPageViewController.
To explain the extra functionality I'll provide a scenario & a diagram:
In A the app is currently showing the first view controller. I then drag from right to left which will of course start to show the second viewcontroller as shown in B. If I stop panning before the point where the UIPageViewController decides whether or not to show the second view controller or go back to the first one I'd like it to instead show the second viewcontroller (taking up one third of the screen) instead of hiding it completely.
If I was to keep panning a bit further beyond the halfway point and then released I'd like the second view controller to take up two thirds of the screen, while the first view controller takes up one third.
That's essentially it. I'd appreciate any advice on how to go about doing this. I'm thinking I'll subclass UIPageViewController and override the delegate methods, but I'd really appreciate any advice on a better solution.
Many thanks
Maybe this could give you a hint or and inspiration. >>
http://www.raywenderlich.com/78568/create-slide-out-navigation-panel-swift

Adding a subview that stays in place as you navigate through views

I am looking to create a subview that looks like a banner drop down view from the Navigation Bar.
or like this
I feel like I see this effect all the time but have been struggling for a while to recreate this. I have it working on single view applications but I would like it to stay in place as I navigate from view to view. Right now I have the view setup in the storyboard and would like use this because I had issues attempting this programatically.
To create this "drop down banner view" and have it stay in place (until the user dismisses it) as a user navigates from screen to screen I see two solutions, each of which I have stumped myself on.
Create my own master view as the window.rootViewController
I see this as the cleaner solution in the end, but a bit harder to implement. Would it be possible to create a blank UIView as the rootViewController and whenever the app needs to drop down an alertBanner it could tell the rootController to do so? The view hierarchy would be something like
window -> masterViewController -> alertBannerController -> Navigation Controller -> otherViewControllers
but I cannot seem to have this set up the proper way.
Create an instance of my AlertBannerView from a subclass of the UINavigationController
Instead of calling the method to create a dropDownBanner from the rootViewController another option I see is subclassing the navigationController to be able to drop down this subview. This way it could still persist as the user navigates around views.
Once again I am having problems setting this up properly to work with the existing NavigationControllers
Conclusion
I do not know what is the best approach here.
This is different than the Apple Push Notifications drop down screen because I would like to customize it for the apps UI
Any tips on how to properly set up a custom view as the rootViewController would be great (where do I do this? what methods do I need to call?)
The problem to solve here is to have the alert banner view remain in the window until the user dismisses it even if they are navigating from screen to screen.
Thanks!
Depending on which version of iOS you're working with, yeah there are a lot of possibilities and ways of doing this. In fact, there are a lot of people who already have.
Best place for getting some ideas on how to attack this problem, to me, is by looking at an existing solution. CocoaControls is a great place for this.
For instance, here is a relatively recent one: https://www.cocoacontrols.com/controls/mpgnotification
And here is a list of a bunch of them ( they aren't sorted in any particular order unfortunately though ) : https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=notification

Resources