UITableViewController with Storyboard - ios

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.

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.

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.

Change TableView Size When It has AN XIB

My UITableViewController class uses an .xib. I would like to make the TableView only take up half the size of the screen, so that I could add more to it. Is there anyway to do this, or do I need to create it all in code, and not use .xib.
This thread covers a similar situation. In practice it would be easier to use a standard UIViewController and implement the UITableViewDataSource and Delegate methods manually.
you cannot resize the UITableViewController class,if you want to add something under table place it at it's footer.
You Can also declare UITableView in UIViewController through XIB through which you can resize it.
in .h File
IBOutlet UITableView *tView;
and connect it to file owner
Thanks

iOS - Having 2 table views and other elements under one TableViewController

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?

Resources