I have been watching a lot of tutorials on Table Views, table view cells etc. When creating a table view why choose a UIViewController over a UITableViewController in Xcode? For instance what would be the main benefits of creating a UIViewController and then adding a tableView object, over just creating a UITableViewController? I have already created a large numbers of scenes within storyboard and I hope I haven't limited myself in doing so. I hope my question is clear as I am new to coding!
UIViewController gives you more control over tableview rather than UITableViewController. You should use UITableViewController only when you are just concerned with tableview in a controller. But if you want to add more subviews/controls in a controller other than tableview, then you have to use UIViewController.
EXAMPLE:
If you just want to display grocery items list with some header and footer, then tableviewcontroller should be priority. But if you want to display mail items in tableview, you would need some additional buttons for altering items in mail(tableview). For later case, you will use viewcontroller. Hope my point is clear.
I think the benefits of having a View Controller is just more versatility and you will have a easier time to add other views other than the UItableview. Whereas UITableViewController i just inheriting a UIViewController, but with the delegates already set up for you. Basically it is assuming you will have a UITableView for sure. In the end it shouldn't really limit you, just cause you used UITableViewController, since everything you want to do in UIViewController, you can do in UIViewController.
Related
I'm working on swiftui views instead of traditional viewController, i used UIViewRepresentable protocol to wrap the GMSMapView. Now i would set a GMSMapViewDelegate to the represented mapView. the traditional way is to implement the protocol on the ViewController that contains the mapView but here while i'm using Swiftui views i'm really got lost. i tried to implement the delegate on a separate class but it did't work for e and couldn't get the current camera target when i moved it.
Please can anyone guide me, this is my first steps in iOS development.
Thank you all.
Thanks all for giving intention to my question, finally i solved it.
Just created a class that inherit from GMSMapViewDelegate and made it as an environment object so all views can access it.
best wishes to all.
I'd like to be able to layout my view controller in code but see the layout displayed in interface builder.
I know I can create a UIView subclass, make that IBDesignable, and assign it to the view controller's view, but this would require that I make all other subviews properties of this UIView subclass instead of properties of the view controller.
The real desire is to be able to layout my view controllers in code but quickly see any changes without rebuilding the project. If this is possible with playgrounds instead, an answer describing how to do that would also be appreciated.
Thanks for any suggestions.
I found a workaround to test view controller layout using IBDesignable.
1.Layout your view controller in code just as you'd do normally
2.Create an IBDesignable UIView subclass and add the view controller's view as a subview.
3.Create a xib and set the class of its view to the subclass you created in step 2
To elaborate on step 2, your IBDesignable's initWithFrame: method may look like
{
self = [super initWithFrame:frame];
MyViewController *viewController = [MyViewController alloc] init];
viewController.view.frame = self.bounds;
[self addSubview:viewController.view];
return self;
}
So beyond this initWithFrame method, all of your layout code can be handled by your view controller. You may want to pass data to your view controller in your subview's prepareForInterfaceBuilder method.
In order to layout you own classes in Xcode you need first to import then in your swift playground: here more information.
After you do that, it's came the "tricky" part. In order to make your how class debuggable and visibile in playground, your class must conform to the protocol: CustomPlaygroundQuickLooacable:
Here there is a quick example from the WWDC:
By implementing this protocol, you're basically telling playground how to represent you hown class. I haven't fond any better solution yet.
I want to programmatically move from a viewController to another using Apple's new Swift language. I've googled and read through the docs, and I see how to use a single ViewController. Does anyone have an example or documentation on how to switch between View Controllers?
There are many ways to do this detailed in the class documentation for UIViewController.
Example 1
Here is an example of using the -presentViewConroller: method (assuming this code is written in a UIViewController subclass):
var secondViewController = UIViewController() //create your second view controller.
self.presentViewController(secondViewController, true, NULL)
Example 2
This is how you would present the second UIViewController via storyboards (again assuming this code is written in a UIViewController subclass):
self.preformSegueWithIdentifier("segueIdentfier", self);
I have this a simple question: How do I resize a UIViewController's view from a custom UINavigationController, since it's not working to simply set it's frame.
I have tried to, in my UIViewControllercategory, override setFrame of all UIViews, which didn't go well...
In a tableViewController I know I can set the tableview's contentInset, but that doesn't really help me here.
I think you can add another view to your UIViewController 's view's subviews. Then change the frame of this internal view is easy.
Hello stackoverflow fellows!
Please consider an UI workflow in iOS:
One main viewcontroller and several other viewcontrollers branching out from there:
mainviewcontroller
+-viewcontroller 1
+-viewcontroller 2
+-viewcontroller 3
etc.
I would like to be able to switch and switch back from the main viewcontroller to one of the other viewcontrollers AND also switch BETWEEN the other viewcontrollers.
All iOS patterns I know of seem to be problematic for that usecase:
UITabbarController would be the right choice if I could make the
tabbar disappear - it doesn't fit to the design. I was able to hide
the bar, but the viewcontroller screens don't resize themselves and
the whole thing feels hackish.
UINavigationController is designed for a sequential order of
screens, also the slide-in animation doesn't fit to the design
Modal viewcontrollers are also meant for a sequential order, additionally I have to keep
track of how many viewcontrollers are on the stack. Also, there is a
timing problem with dismissing a view controller and immediately
presenting the next one.
I could just switching views within a viewcontroller I guess, but the
viewcontrollers have all kinds of subtasks to do. I would end up with
one huge viewcontroller and lots of methods embedded for the
different views.
My question:
What would be the best approach to manage a bunch of viewcontrollers in any order I would like to?
Thanks for any help!
I would have a main UIViewController. That one would have references to the other three UIViewControllers. You can then do something like this from inside your main UIViewController:
[self.view addSubview:view1.view];
This works, but I wouldn't advise you doing because it's not the natural way of doing it. As stated by apple:
You should not use view controllers to manage views that fill only a
part of their window—that is, only part of the area defined by the
application content rectangle. If you want to have an interface
composed of several smaller views, embed them all in a single root
view and manage that view with your view controller.
Ok, my solution is not perfect, but seems to work:
Create a UINavigationController.
Use the viewcontrollers: method to add a stack of viewcontrollers to your liking.
When switching between viewcontrollers, rebuild the stack and attach again.
Problem: You only have the navigation controllers animation (slide in/out) at your disposal.
But you can disable the navigationcontrollers animation, get the next viewcontrollers view, animate that in with a UIView animation, then switch to the view controller itself through stack building as explained above.
Really far from perfect, but works.