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

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?

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!

Best approach for 1 screen contains 2 view controller

I want to learn parent - child concepts in iOS. I found a some app in app store and I liked the their design. They have 3 button in same view controller when the user taps a button below view changes and calls their view controllers. Like a TabBar.
I tried to create 3 xib files. When the user taps the buttons they are awaking from nib and I added them to my containerView subview. It works. But I couldn't send a data between them because there is no prepare for segue method to so i couldn't prepared them.
I tried to create 3 viewController in Storyboard and I use them with the Storyboard ID. It works. But still can't transfer data between them.
I didn't understand what is the best approach for solve this problem ? I researched on the web about Custom Segues and Parent - Child concepts but I couldn't find anything.
What is the best approach for make a container like in the image ?
Thank you.
I am not sure if there is something like a best approach, at least in general term. It really depends on your specific demands and other logic of your app.
Both creating XIB files and creating ViewControllers in Storyboard together with their ID is ok. Here it is more about your preferred way. I would say that today you will probably see more using Storyboard than XIB files.
In terms of data transition. There are several ways, if it is not some very heavy logic then delegates can do it pretty well and easy.

How to segue to View Controller from skview

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

Multiple Segues to one ViewController with NavigationController?

i have one question about using multiple segues to one ViewController. Ill try to create an article management, so you can add/edit/delete articles.
When you add a new article you can choose between a maincategory and a subcategory, choose the article and then edit some inital values.
but if ill try to edit one of my selected articles, i would like to jump to the "latest" ViewController in navigation stack.
I thought i could easily create another segue to my last viewController, but ill always get an error when i try to load this segue (i guess this could be a problem with the existing NavigationController).
I could provide some code, but i dont know if this is a possible solution to solve such things - or is there a better way?
Thanks in advance.
You can, but the new segue should take you to a navigation controller that just contains the last view controller (as the root). In this way you are duplicating the normal situation but with only 1 view controller.
If you wanted to allow the last view controller to have a 'back' button which took you to some 'earlier' screens (if that makes any kind of sense in your app) then you would need to write some code. It's more likely that other screens should be accessed via bar button items or similar (which would also likely be done in code).

UIStoryboard Segue Shuffle

New project, using storyboards for the first time. So many things I did easily with nibs is frustrating me to no end.
I want to be able to hop around and shuffle my views at will. I have figured out unwinds and pushes and all goes well as long as I continue linearly forward in the storyboard path. At some point I want to hop laterally back to a view that may already be somewhere on the stack, or not. This doesn't seem to work as expected.
Using UINavigationController.
Say, at one point I have 3 different views moving forward. I push one of them and go about business along that "fork". Now at some point I want to hop over to one of the other 3 paths at that fork without backtracking through the stack.
Previously, I might just instantiate the correct view controller from nib, push, then remove the view controllers from the stack that are between the "fork" and the current view. Or, if that view controller was already on the stack, I could shuffle it around by manipulating the array directly.
How can I do this with segues?
I tried making segues to and from each of the three view controllers at the fork. What a mess. I keep getting errors, segue not found, when I know they are there. I tried "replace" segues, they didn't work as I expected. Not to mention my storyboard looks like a spiderweb.
I don't like to be stuck in the old ways. If storyboards are the future, I want to be on board sooner rather than later but I could have been so much further along if I'd stuck with what I know. Any storyboard wizards willing to school me with suggestions?
Since nobody answered, my solution turned out to be abandoning the navigation controller entirely and use a variation of the method detailed here by Michael Luton:
http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers
If anyone has need for this, I can say that it works very nicely and is quite simple to implement.

Resources