referencing outlets with new view controller table view - ios

I've an button in my storyboard's main view. now I need to open an new table view in new screen when this button will be clicked. For this, I've
1. dragged an new view controller in the empty space on storyboard.
2. dragged an table view inside this new viewcontroller.
now not able to define this new table view in ViewController.swift. ctrl + drag from table view to ViewController.swift not opening any dialog.
any idea what wrong am I doing here.....

From the details you have given, it looks like you have not set your viewController Class. Create a custom view controller class. Specify this class as the custom class in the Attributes inspector for the viewController scene and try adding your tableView.

Related

Adding Custom class in TableViewController in swift

I've been trying to add a custom class named ThirdViewController to My TableView controller which is a third tab of my Tab Bar Controller. When i try to use a View Coontroller it displays but for table View controller which is required, it doesnt show any suggestion in my custom class.PFB the image for the same. Image here
You can simply try creating UIViewController class and then use UITableView in that view controller

Xcode Storyboard: Can't add View to ViewController

I'm using Xcode 10 (with Swift 5 and for iOS 12) and my app is currently set up like this:
UIViewController 1 (login screen) - segue12 to ->
NavigationController that automatically created
UIViewController 2 with a UITableView - segue23 to ->
UIViewController 3 (detailed info about an item in the UITableView with automatically created "back" button)
The NavigationBar only contains a " ".
I now want to add another UIView with a button below the UITableView but Xcode won't let me drag it below the UITableView, only either into the UITableView or directly underneath "First Responder", which puts the View outside into its own window.
If I delete "My Table View", it won't let me drag in a replacement either.
How do I fix this, so I can add the new UIView + UIButton?
NavigationController that automatically created UIViewController 2
That explains everything. When you drag a navigation controller into the storyboard, what you get is a navigation controller and its root view controller, and the root view controller is a UITableViewController.
Let's step back for a moment. A view controller can and must have exactly one main view. It occupies the whole scene. It cannot be resized. It cannot have a sibling view, because it has no superview for a sibling view to be a child of. It can only have children (subviews).
Well, in this case, ViewController2 is a UITableViewController, and MyTableView is ViewController2’s main view. (A table view controller is always configured this way, and that is what you got when you dragged the navigation controller into the storyboard.) That is why you cannot add more views to it, except as subviews, e.g. prototype cell contents. Your button has no place to go except inside the table view.
So, what to do?
If the extra interface you want to add is just a button, the usual solution is to put it into the navigation bar. It becomes part of the table view controller's navigation item.
If you don't want to do that — that is, if you really want the button and the table view to be siblings of one another in the interface — then you need to replace ViewController2 itself with an ordinary view controller. Now its main view will be an ordinary view, and you can drag anything you like into it, including a table view and a button. More likely, instead of a bare table view, you would use a container view, with an embed segue to a table view controller.

How to work on View added outside to the main view of ViewController in Storyboards?

I have created a registration form and in which user can select his Gender. On tapping the button of Gender, I need to show a custom view. I want to use Storyboard for creating view but I cannot work on that as I cannot see it without adding that on the main View of the View Controller. Please see the image below. I want to keep that view separate from the main view of the View Controller and I will add that view programmatically when user will tap on the gender Button.
You can't add a UIView to the canvas in storyboard, it needs to be contained in a UIViewController.
Your options are:
1) Create a xib file for your UIView subclass and design it there.
Then import it by calling -loadNibNamed: on the main bundle.
2) Do the design layout programmatically inside your UIView subclass.
3) Add a container view to your main VC and use the view controller it generates to design your gender view. Then you can start with it hidden and show it when the gender button is tapped.
• Put it as a subview
• Design it
• Put it back there outside of the view controller

How to add view with buttons (target-action) to a scroll view

I have created a custom UIViewController with its view in a .xib file created in Interface Builder. The view looks like this:
The view has a UIButton with a target-action pair. The action is a method in the view's view controller. I want to add this view to a UIScrollView, so I created a simple custom view controller which just has as UIScrollView in it. I added the first view controller's view as a subview to the scrollview and set the content size properly.
Everything now works fine, except that when I press the button the application crashes and the 'EXC_BAD_ACCESS' warning comes up with error code 2.
How can I solve this?
There is an action in your view controller that you assign to your button ?

UITableViewController inside a UIViewController

I'm new to iOS and objective-C and I'm having some trouble in understanding how controllers work.
In my code I have a UIViewController (with my custom controller assigned by storyboard) and inside it, together with other objects, I want to have a table handled by a different controller. What is the right way to do this?
You can make that table view controller a child view controller of your UIViewController.
In the storyboard, you can do this easily by dragging a container view into your controller's view, and that will give you a child view controller automatically.
You'll want to:
delete the child view controller it gives you (it's just a UIViewController)
drag out a table view controller
control drag from the container view to the table view controller
choose "embed".
If you need to get a reference to this table view controller from the UIViewController, you can do that in prepareForSegue -- the table view controller will be the segue's destination view controller, and prepareForSegue will be called right after the controllers are instantiated.
You'll want to use an embedded container view.
Drag a "Container View" from Interface Builder sidebar into the view. This adds and links a default "contained" UIView/Controller as well.
Delete the entire UIViewController and View that was automatically added and linked to the container view (as you'll want a Table View Controller instead).
Drag a UITableViewController onto the Storyboard canvas.
Control-Drag from the Container View to the Table View Controller. Select "Embed" to contain the UITableView within the container view.
You're left with the parent view, now containing a UITableView via a Container View. The Controller for the Table View is on the storyboard canvas as well.
Add UITableViewController to storyboard, And create subclass (new file) of UITableViewController. In Storyboard go to Identity Inspector and in Class field type name of the subclass you created. After that you have to add your app logic based on your requirements.
Create Another UITableViewController in the storyboard, go to its inspector and assign it the same UITableViewController class that you have created before...

Resources