No content attribute for UITableView in .xib - cocoa-touch

(XCode 4.2, iOS 5)
In order to reuse a tableview (with a navigation bar and edit/add buttons) I created a UITableViewController subclass with it's own .xib. However, when I add a UITableView to my .xib's main view the content attribute (which I want to set to dynamic prototypes) it doesn't show up. It just shows the sample content (California: Brea, Burlingame, ...). When I add a UITableView in my main storyboard the content attribute does show up.
What is the issue?

For people trying to solve this, it is impossible to set dynamic prototypes cells in a .xib, or even static cells. No embedded sections or cells are supported in .xib files.
If you drag a Table View Controller into a .xib, you'll get an error:
Table views with embedded sections and cells are only supported in
storyboard documents
Xcode 6.3.2

Related

iOS9 - UITableViewCellContentView is covering up Controls inside Cell

I have made a custom UITableViewCell called "SwitchCell" that has a switch.
In iOS9 Only, using Xcode 7 beta, the Content view in the cell is on top of the switch. (See screenshot of View Hierarchy. You can clearly see that the content view of the cell is on top of the other views. ):
So all the touches to the UISwitch are intercepted, and the IBAction does not fire.
In iOS8, this is not a problem. See screenshot for iOS 8.4 simulator. You can see that there is no content view on top of the controls:
Has anyone had this problem?
I tried remaking the NIB from scratch, but the same result occurs.
My NIB is a freeform size view with No status bar. It has two outlets: one for UILabel, one for UISwitch.
EDIT: please make sure to check the answer below that asks to verify that the cell's root view is not just a UIView but a UITableViewCell. This issue may also be a side effect of this.
After more investigation and searching, i found my solution here:
Button in UITableViewCell not responding under ios 7
What fixed it for me was:
cell.contentView.userInteractionEnabled = NO;
This prevents the cell content view from taking over the touch events, even though it's on top of the other views.
This issue was not only happening on iOS9, but on iOS7 as well. In iOS8, the Content view was behind the controls.
Problem can be in .xib file for your cell. When you create cell in separate .xib, be sure to drag UITableViewCell on canvas, not UIView.
SWIFT
I had an issue where my buttons in my custom tableviewcell swift files were working just fine, but then I upgraded to Xcode 12 and then all of a sudden I couldn't access them anymore (meaning my taps were not being recognized). The cell content view seemed to be interfering in the hierarchy and this like saved me:
cell.contentView.isUserInteractionEnabled = false
I put the line in cellForRowAt.
Thank you to #FranticRock
I had this problem when I was reusing a cell as a .xib. I didn't realise but when I first created the xib the default view that it created was in fact a UIView and not a UITableViewCell. It seems that at some stage UIKit adds the content view on top of my other elements and therefore interrupts certain events (e.g. touch events).
I resolved this by opening my xib file and dragging a UITableViewCell onto the canvas and copying my UI elements from the old view to the new cell.
Afterwards, additional settings also became available in the attributes inspector that matched those for a UITableViewCell.

linking header and main files to story board xcode

I am pretty new to xcode and for the life of me I cannot figure this one out. I am adding a view controller to a storyboard and I am trying to add a picker to that controller, I have the code in a header and main file I created but how do I link those files to the viewcontroller in my storyboard?
Here is how:
Create a custom UIViewController subclass for your code, eg MyViewController.h and MyViewController.m
in the storyboard drag out a ViewController
(i think you have done both of these steps)
in the Identity Inspector (panel 3 of left-hand side Utilities panels), under 'Custom Class' you should see your class in the scrolling list. Select it.
Then you will want to make links between your picker in the storyboard and your code....

Storyboards and Table View Sections

I've noticed that in Storyboards, when dragging out a Table View object from the Library, you also get a chance to configure table view sections, and bunch of other options. For example, if the content is going to be static cells or dynamic prototypes, etc.
Here's a look at the Table View in Interface Builder (.storyboard file):
and here's how the Table View looks like in a .xib file:
So my question is - is it possible to configure/style (drag buttons, images, etc. into cells) a table view in a .xib file using Interface Builder or it can only be done programmatically?
Can be done either way. I prefer doing it in IB as the layout is much easier when you can see what you are doing. For dynamic prototypes, you only design a single cell and the contents will be populated in the cellForRowAtIndexPath method. With a Static Cell tableview, you can design the whole thing (many sections and many rows). The requirement for a Static Cell tableview is that the class HAS to be of type UITableViewController, while for Dynamic Prototypes, it can be either a UITableViewController or (my preference for more flexibility) a UIViewController with a UITableView.
Hint - if this is a Static cell tableview and you only design a screen full of sections and rows, be sure to turn off scrolling for the tableview.

How to show a .xib file in a TableViewCell

I have a .xib with an image and a label in the potition that i want..
And i want in the cellForRowAtIndexPath function to set image and label.text then to add then view in the cell and show the cell
Check this:
How do you load custom UITableViewCells from Xib files?
But i do not recommend to load UITableViewCells from xib.
You loose performance on a very critical part.
I recommend to create you UITableViewCell subclasses by code. Because inflating a XIB(XML) during scrolling will create buckings.
If you wan't to have a nice, snappy app, then code instead of XIB (at least the UITableViewCell subclasses).

How to resize view in XIB?

I'm trying to follow these instructions with Xcode 4, but am unable to resize the xib. Does anyone know how? ( The width and height cannot be clicked upon ) Also there is no UITableViewController so I just used UIViewController.
EDIT - My goal is actually not to use the popover controller, I simply want to create a modal login dialog following the example here: How to resize a UIModalPresentationFormSheet? and am trying to make the view controller 300x400
A popover controller has to have a
view controller inside of it. So we
need to create a new view controller.
Go to File > New File > Cocoa Touch
Classes > UIViewController >
UITableViewController subclass >> With
XIB for UI >> Targeted for iPad. Name
it OptionsViewController. Drag your
viewcontroller.h and viewcontroller.m
files into the classes group and the
new XIB into the resources group.
Open the XIB and go to the Size
inspector. Change the width and height
properties to 250 and 300. Save your
file and close interface builder.
It appears that in Xcode 4.5+, just to be annoying: Apple changed this again.
Instead, you now have to:
select the viewcontroler
select the "size" dropdown
set it to "Freeform"
...which removes their "block" on editing the size fields.
(this is pretty close to how I expected it to work in the first place, but I have to say it's not easy to find - you have to edit a different value on a different screen (with no help from Apple), in order to un-break the edit field on the correct screen. Not good design!)
Interface Builder (and the IB equivalent in Xcode 4) won't let you change the size (or autosizing attributes) of a top-level view when any Simulated User Interface Elements are enabled.
Select your view, and in the View Attributes inspector set Status Bar, Top Bar, and Bottom Bar to Unspecified. You should then be able to change the size.
In swift 4.2 interface builder won't let you change the size
click on the view and open the attribute inspector and change top, bottom bar to none and size to freeform. Now you are good to go for the change in size.