I know that it is not possible to add a static UITableView inside an UIViewController (or at least I could not find any way to do it). Trying to do a workaround (as pointed here), I am following these steps:
I have created an UIViewController on my Main.storyboard.
I have drag an UIContainerView inside my UIViewController.
I have deleted the UIViewController embedded by default on my UIContainerView.
I have created an UITableViewController and drag it to the UIContainerView.
I have added a label with the text "Hello" into my UITableViewCell.
Here is the structure of this part on my Main.storyboard:
And here is the result that I am getting:
I can only get an empty UITableView without any information inside of it.
Am I missing something? Am I doing it in the wrong way?
P.S: I am using Xcode8 and Swift3.
Thanks in advance!
You are using a UITableView with Prototype Cells which is visible because in the grey area it's written "Prototype Content".
Change to Static Cells in the Table View inspector (on the right of the window) after selecting the TableView in Interface Builder.
Related
I have a subclass of UITableViewController.
I overrid initWithCoder so that when the controller initializes it adds five items to the UITableView that it creates by default (I did not create a UITableView in IB because the UITableViewController creates one).
I would like to add a header (with 2 buttons) that I created in Interface Builder to that tableview.
I linked an IBOutlet to the header from Interface Builder and I set it to be the header of the UITableView created at initialization.
The problem is that although I did this I only see the UITableView with the 5 items (displayed corectly) but I don't see the header. It's like it ignores the header from the Storyboard or something like that.
Any idea why?
Thanks.
I just captured one GIF from of my example StoryBoard that you can drag UIView on top of your UItableViewController and make it resize as par your need. pelase check following.
Hope that help to you. After drag view on UITableview you just need to create IBOutlet and make your task complete :D
Drag a uiwebview into right above the tableview's first cell.
After the new Xcode update, my app doesn't validate and shows this error:
static table views are only valid when embedded in UITableViewController instances
Any chances to solve easily?
The only way to get a static UITableView along with other controls on the same screen is to use a Container View. Follow this way, it works perfectly:
Drag a ViewController onto your storyboard.
Drag a TableViewController onto your storyboard.
Next Drag a Container view to your ViewController and size it about the size you want (smaller than the view) -> when you drag the container view it will create a segue and another view. Remove that segue and view.
Then finally ctrl click in your container and drag to your new TableViewContoller. Select Embed.
Style your TableView the way you want -> including static cells.
This answer was already found and given here: G.Huebner -> http://web.archive.org/web/20140928102504/http://iphonedevsdk.com/forum/iphone-sdk-development/111800-static-table-view-cells-only-work-in-a-uitableviewcontroller.html
A static UITableView must be in a UITableViewController. So you will have place the table in UITableViewController and then add it as childView to the MainViewController.
You can refer
https://iphoneidoit.blogspot.in/2013/10/static-uitableview-in-uiviewcontroller.html
I think what you are doing is you are first dragging the ViewController on the storyboard and then dragging the tableView on the ViewController. In this way you can't use the Static table cells. Instead of this what you should have done is Drag the TableViewController on the main storyboard instead of a ViewController and then select the static cells. In this way you can be able to work on static cells and can use any elements on static cells.
Well, if you are really using a static tableView, you should consider copy/past everything to a ScrollView or StackView.
Using storyboard in ios7 the content view is explicitly viewed under the Table View Cell in the story board editor (opposed to previous versions where it was hidden from the interface).
The problem is that I cannot connect the cell's custom elements to my custom cell's ib outlets anymore (subclass of UITableCellView) and can only connect them to the table's content view (UIView) which CANNOT be customized (i.e. its custom class attribute is grayed)
This leaves me with the option to use tags which I find inconvenient and less elegant.
I could also create a custom view in a xib, do all the connections and then manually add this custom view as the content view of the table but I am looking for a way doing it via the story board editor.
Is there a way to connect UI elements to a custom cell's content view in the story board editor in ios7 ?
Ok I found an Xcode bug.
If you complete the following this will replicate the issue:
- Create new UIViewController in storyboard
- Drag a UITableView to the VC
- Update the UITableview to have 1(as many) dynamic prototype cells
ISSUE: The cells are added but without a contentView.
RESOLUTION:
Rather than updating the amount of cells in the storyboard.
Drag a custom cell from the objects part of Xcode, the Cell will be added with a contentView.
I was able to do this by doing the following:
Select the cell in the document outline
Change its custom class in the Identity Inspector
Place whatever elements you want into the content view
Connect the IBOutlets to the elements inside the content view using the Connections Inspector
I don't really know the answer, but I can suggest work around this issue:
1) Copy existing cell from other tableview to the one you're working on.
2) You will have contentView under your cell now. Design this cell by adding your views.
3) Create a class for your cell, e.g NewCell, then manually create IBOutlet in this class:
#property (nonatomic, strong) IBOutlet UILabel* mainLabel;
4) Assign the cell class in storyboard to the class you just created. After this step, you can drag the outlet from storyboard to class.
I'm not sure if this is a bug for XCode 5 or it is intended, and I'm looking for better solutions as well.
Create new uiviewcontroller with xib interface and add the required sub-views .Also,establish the iboutlet connections.
Now ,rename the viewcontroller : UIViewcontroller to viewcontroller : UITableviewcell in .h file of your newly created view controller.
Your tableviewcell was created and ready to use with any UITableview of any class.
Hope it helps.
I might be duplicating someone else's answer but I found this workaround which helped bypass this silly XCode bug. Short solution: When you build your custom cell in Storyboard, do NOT drag your UI elements inside the cell or content view.
Instead, drag them OUTSIDE so that they're child elements of the parent table view!
It's easiest to do this drag and drop if you use the little hierarchy menu on the left to make sure your elements wind up in the right spot.
Once the elements are dragged in, just control-click and drag from the custom cell to the UI elements to make your connections. Woo hoo!
Once your connections are set, then (finally) drag the UI elements back INTO the custom cell's content view and lay them out as you normally would.
UPDATE: While my method works, look for a comment by thomasdao in an answer below where he just drags the connections directly into the .h file (the little circles in the left margin where you declare your IBOutlets) -- this is actually the easiest solution but unfortunately it's stuck as a comment.
I want to add a simple static TableView to my UIView. So i dragged it into my UIView. Added the TableViewDataSource and Delegate Protocols to my ViewController class. Created an outlet to my tableview and connected the datasource and delegate outlets to the viewcontroller.
But i still get an error message which says that Static table views are only valid when embedded in UITableViewCOntroller Instances ? Any Ideas how to solve this Problem ?
PS: I am using UIStoryboards for designing the UI
Use a containerView (drag one onto your UIView) which will link to a UITableViewController instead. You will use the prepareForSegue method to initialize the table view controller.
Oh, and you might want to accept answers that help you or no one will help you anymore.
If you want static cells, in your Storyboard, click on the tableview, then in the inspector, change the Content from 'Dynamic Prototypes' to Static Cells. You can also segue these cells to a new controller without having to set up data sources and delegates for the table.
I'm trying to make an interface like this one:
But I get the following error in XCode: Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances
That controller is a subclass of UITableViewController, so I don't really understand what the problem is, any insight?
First of all, I think you're saying that ProfileViewController is a subclass of UITableViewController. If that is the case, the top level view should be a UITableView not just a UIView. And the error does make sense. If you want to create a static table view, it needs to be embedded in it's own UITableViewController, which is what you get when you drag a UITableViewController from the Palette to the storyboard.
Amended to answer question in comments
So starting from scratch. Drag a TableViewController onto your storyboard and change the class to ProfileViewController. That gives you your tableview with the prototype cells. Then drag an empty view to near the top of the TableView. This will add a headerview to the tableView. (Every tableview has a subview for a header and a footer. This is different than the section headers). Now make that header view taller and drag your other elements into it: the segmentedButton, the search field. Drag your UIImage View. then drag another tableview and position it next to the image view.
Now create a subclass of NSObject NOT NSTableViewController like so.
#interface MiniTableViewController : NSObject <UITableViewDelegate, UITableViewDataSource>
And put the datasource and delegate methods for that minitableview in there. Back on the story board, drag an object to the hierarchy change the class to your MiniTableViewController, and connect the delegate and datasource outlets from your minitableview to the MiniTableViewController in the hierarchy. Make sure you're using the assistant view. Then ctrl-drag from the MiniTableViewController object to the ProfileViewController.h (right before #end) and create an IBOutlet. Now you can access your new custom object from ProfileViewController. You can also create an IBOutlet in MiniTableViewController and connect it to ProfileViewController if you need MiniTableViewController to send messages to ProfileViewController.
A UITableViewController can only have one Table View. You have two. You have to find another way to do it.
Have you put a UITableView in your xib ?
If yes, have you bind this UITableView to your controller?