Static table view outside UITableViewController - ios

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.

Related

How to use a static UITableView inside a UIViewController?

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.

Can't change the size of a TableView in Interface Builder

I'm trying to change the size of a tableView I have in interface builder and can't seem to. When I first started the app I could drag it around and stretch the sides but all of a sudden I can't adjust it. I tried to delete my tableView and add a new one but the same thing happened. Thanks in advance. Here's what I see when I try to change the size:
if your using a UIViewController you can drag and drop a tableView and can place in a custom position you want. but if your using a UITableViewController you cant move the tableView to your custom position. if you want to do it in UITableViewController you can do like below
if you want your tableView content should show from a point, that you want you can do this way,
[self.tableView setContentInset:UIEdgeInsetsMake(100,0,0,0)];
else if you want set your tableView to a frame in UITableViewController you do this way,
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.tableView.frame = CGRectMake(0,100,320,300);
}
hope this will help you.
What kind of view controller are you using to manage your table view? Since you show "prototype cells", I'm guessing it's a UITableViewController. Those are built to fill the entire screen with a single table view (which has always annoyed me.)
Starting with iOS 6, though, you can create a "container" view in another view controler, and then drag an embed segue from your container view onto the table view controller. That does all the housekeeping to make the table view controller a child view controller of the other one, and then you can make it whatever size you want.
If you don't want to use a UITableViewController as a child of another view controller, you can use a regular view controller and wire up the data source and delegate methods yourself. However, things like static table views and prototype cells don't work then.
Hopefully this helps someone still coming across this problem. What I did was make sure the UIViewController had a UIView as its direct child, then dragged the UITableView as a child of the UIView, this allowed me to resize the UITableView.

Floating button over UItableview using storyboards

I have made a table view using prototype cells on tableviewcontroller from storyboards.
I want a floating button over that uitableview. (button won't scroll with the tableview).
While searching for a solution..I found out that it is possible by adding button to the superview (in that case Uiviewcontroller subclasses Uitableview).
Can any one tell me how to do that using storyboards??
I think best thing you have to do is to create a UIViewController and add it a UITableView. Then you can add also the UIButton you want to the view controller's view. Don't forget to set the view controller to be the delegate and data source for your table view, and to add <UITableViewDataSource,UITableViewDelegate> to your view controller interface.
If you must do it using Storyboards and not in code, then you need to use a UIViewController and not a UITableViewController.
Add the UITableView and make it full screen - link up its Delegate and DataSource to the UIViewController and adhere to the two protocols in the .h file of your UIViewController.
When adding the button, drag it into the view hierarchy in the "Document Outline" sidebar, and not by dragging it onto the UITableView. Be careful if you're ever dragging the button around the view because if you drag and drop it on top of the UITableView then it will become a subview of the UITableView. If you want to move it around you'll need to select it and then use the arrow keys.
Anyway, apart from that it should all be very easy - add your constraints to keep it in the right place and you should be able to use the button as normal.

ios 7 customizing UITableViewCell's content view

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.

How to use a TableView inside a UIViewController?

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.

Resources