Grouped UITableView - remove 'Prototype Cells' header in interface builder - ios

I have a UITableView placed on my view controller in IB, using 2 prototype cells and 'Grouped' style. There will only ever be 2 cells in the table, and no group header so I want to resize the height of the table view control to be just tall enough to accomodate the 2 rows (each of height 29) so I have room for my other controls on the VC. Problem is, when I resize the height of the table in IB, it always shrinks at the bottom and retains the 'Prototype Cells' label. This means to get the right height and position I have to lose visibility of my cell designs - see screenshot :
Is there anyway to turn off the 'Prototype Cells' group header label so I can resize my controls WYSIWYG style?

It will be more useful to show your code and what UITableView delegate methods you have implemented in your VC. Anyways, try this : set your header #property for the tableView to nil and if you get no result implement this:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return nil;
}
Hope this will work. Cheers

It is possible to change the uitableview to static in stead of dynamic cells. This allows you to add the cells in the layout editor. You can then make iboutlets to the cells and there content. The downside of this is that you will have to use a UITableViewController as root which in turn doesn't let you add anything else then cells, headers and footers.
You can still add the rest of your components in a separate sections and just set the cell to background to invisible. or you could load the controller grab the view and resize it and add it to another viewcontrollers view.

Related

UITableViewCell size does not follow Content View size

I have two UITableViewControllers which use the same set of cell templates, therefore I have created a table view controller in my Storyboard which contains these templates. My table view controllers instantiate an instance of this template holder tableview, then in -tableView:cellForRowAtIndexPath: they deque one of it's cells, and configure it as they need.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *widgetDict = [self.widgets objectAtIndex:indexPath.row];
DMSWidget *widget = [self.widgetStorageTableViewController.tableView dequeueReusableCellWithIdentifier:#"Key Value Row"];
...
return widget;
}
These cells have their inner layouts set up entirely using AutoLayout.
Everything works fine, except that I get cells which have the standard 44 px height and width of the table view, with Content Views narrower than this (depending which they contain, the ones with less contents are smaller), and are longer than the cells themselves. So the Content Views overlap the next cell but don't fill the entire width.
I don't understand, how this could happen. How is it possible, that the UITableViewCell has different size than it's Content View? They should be the same, isn't it?
What I tried to do but failed:
implement -tableView:heightForRowatIndexPath:: tried to return UITableViewAutomaticDimension, but did not help
reload my table view when the sizes are calculated: does nothing
add hacks to cell implementations, like setting autoresizingMask in -awakeFromNib: I could make the Content View expand to the width of the cell itself, but it was still overlapping to the next cell
UPDATE: It looks like it is not related to the dual table view architecture. When I copy my cell to the tableView where it will show up, has the same issues.
I've found the solution: it was all my fault. In some of the ancestors of my cell has an init, which called -initWithFrame: explicitly with CGRectZero. After removing this, iOS 8 could use it's frame values and everything worked fine.

Scrolling in iOS for a component with variable height

I am trying to make a vertically scrolling view, where the screen has three sections and scrolls up or down in totality (i.e. all the three sections move up and together together)
There are three parts of the screen - Section 1, 2 are fixed height and section 3 is scrollable depending on the number of row data that the server sends to the client
How do I achieve this in iOS - is there a way of having
Parent View
Section 1
Section 2
Section 3
and then call scrolling function on the Parent View? I don't want to go into the messy details of manually adjusting the height of the Parent View by checking the Section 3 height (variable) and adjusting accordingly - surely there is a way in iOS programming to encapsulate all this behaviour in a clean little class. Thanks for the advice
This behavior can be realized with native iOS components.
There can be different implementations but I would choose this one:
UITableView
HeaderView
UIView (Section 1)
UIView (Section 2)
Content View (Section 3)
UITableViewCell (Section 3 cell representing your first row data)
...
In Xcode Interface Builder, you can add an header view by dragging a view on top of the displayed prototype cell.
With this architecture, the HeaderView will have a fixed height, and the ContentView will have a dynamic height. And when you scroll, the whole UITableView will scroll.

How to add a subview to a UIView's contentView in a UIStoryboard? (iOS)

I have a UITableView that I've created in a UIStoryboard. It contains one Prototype UITableViewCell. The cells are populated in the ViewController's cellForRowAtIndexPath: method.
I'm now trying to add the ability to delete cells using commitEditingStyle:forRowAtIndexPath:. Everything is working except that when the delete button animates over the cell, the rest of the content doesn't shift over and it looks really ugly. According to this SO question, content will only be shifted if it's added to the cell's contentView rather than to the cell itself.
As such, is there a way to add a UIView (Ex. a UIButton) to a UITableViewCell's contentView within a UIStoryboard?

iOS- How do I make each cell in a table view bigger?

This might be a noob question,but how do I make each cell in a UItableview bigger through interface builder?
Select the table view in your nib or storyboard. Then show the Size Inspector. (You can do this by choosing View > Utilities > Show Size Inspector… from the menu bar, among other ways.) The first section of the Size Inspector is the Table View Size, and the first field in the Table View Size section is the Row Height.
Changing the Row Height field in the nib has the same effect as setting the rowHeight property of the table view instance at runtime.
If you want rows to be different heights, you must either implement tableView:heightForRowAtIndexPath: in your table view's delegate, or use a storyboard with static cells.
Assuming you have set the dataSource and delegate to self, this should work:
- (CGFloat)tableView:(UITableView *)tableView heightForCellAtIndex:(NSIndexPath *)path
{
return 50.0f; //Replace with how high you want.
}
Typed on mobile, test before shipping.
Yes, it's code, but it's a whole lot easier than anything else. Easier to change, too.
Select the Table View Cell, then choose the ruler icon on the right panel, check Custom next to Row Hight, then just change the row height.
To change the width select the view controller, find Simulated Metrics in the tab to the left of the ruler, change Size to Freeform, then select the Table View, go back to the ruler tab and you should be able to change the width which the cell will adjust to if Autoresize Subviews is checked (which it is by default).

Static table view cell's height in xib not being applied

I have created a static table cell in a .xib, however when it is displayed the cell height set in the xib is not being applied, instead the cell is being displayed with what looks like the default height for cells.
I have set things up as:
1) The table view controller derives from UITableViewController
2) The TVC is not contained within a xib and is created in code in the app delegate and added to a tab bar controller.
3) The TVC is created using initWithNibName:bundle: with the nib name supplied as the name of the xib containing the table view and the static table cell.
4) The TVC has an IBOutlet iVar of type UITableViewCell*
5) cellForRowAtIndexPath returns this iVar.
6) numberOfRowsInSection returns 1, numberOfSectionsInTableView returns 1;
7) The xib contains a table view, which is connected to the File's Owner's view. The File's Owner is set to my custom table view controller class.
8) The UITableViewCell in the xib is connected to the outlet of type UITableViewCell in the File's Owner.
9) THe Table view style in the xib is set to grouped.
10) The size of the Table View Cell shown in the size inspector is N, and this is where the problem is. If I change N manually or by resizing the cell visual representation then this size is not applied when the table is drawn. I have also tried setting the view Frame Rectangle height in the size inspector to match.
It doesn't matter what value N is, big or small.
11) The cell's height is not being set anywhere in the TVC, if I do set it using self.tableView.rowHeight then its height does change. But I do not want to set it explicitly like this, I want the height size in the xib to be picked up.
This has been driving me nuts for a few days, and reading several tutorials on table views (including Apple's table view programming guide, especially the section on static cells, whose instructions I followed in the first place to set everything up) has not given me any clues where the problem lies.
TIA
Implement heightForRowAtIndexPath and return the height of the UITableViewCell linked to in your IBOutlet.
Do you have - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath defined in your UITableView delegate?
You may want something like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 30;
}
Try this post if you're still having trouble try this post: Setting custom UITableViewCells height
I had the same problem and everyone here and on other threads suggests writing code to fix the problem, which seemed wrong. What's the point of using IB if you have to write code to get the properties right?
The answer turns out to be very simple but took a bit to track down. In IB there are two places that row height can be set (just like there are two places to set it in code). One is on the table, the other is on the cell.
The place I was (incorrectly) setting it was the tableViewCell's "Row Height" property in the Property Inspector. Changing this value had no effect on row height at runtime.
Then I found and set the "Row Height" property of the TableView (one step up the object hierarchy) and viola, the row height is correct at runtime. Once this was working I turned off the override of Row Height on the TableViewCell (uncheck "Custom" on the Row Height property). I was afraid this might be evaluated on each cell, which would kill performance since all my cells are the same height.

Resources