Can't find the .m file for UITableViewController - xcode

I realize this is likely an inane question, but here goes:
I'd like to set the background of a uitableview by code (created using storyboard), however... the only .h file I can find is in the uitableviewcontroller.h in the frameworks folder. There's no .m file anywhere that I can see, and I need to place code in the "viewdidload" for that particular table.
Thanks for any help in advance!

You need to create your own class that extends UITableViewController. There you can override viewDidLoad and put your code there. Then, in your storyboard, set the custom class for your table view controller to the class you created. You do that in the 3rd tab inside the right-side pane.
Even if the source code for UITableViewController were available (and it is not, since Cocoa is a closed-source framework), your changes there would apply everywhere that class is used, which is never a great idea :)

Related

Unable to see custom classes in Interface Builder drop down

I'm using Xcode 6.1.1, and cannot select my custom class from the drop down. Because of this, I believe it is causing several other related issues (see below).
Symptoms:
When using the IB drop down to choose a custom class, none of the custom classes appear.
IB_DESIGNABLE and IBInspectable do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined as IB_DESIGNABLE.
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
Suspected to be related: WatchKit: unable to find interface controller class
How can I fix this?
Things that worked:
Try on another machine. (This leads me to believe the machine has some setting that is messing this up.)
Reinstall Xcode.
Moving the project to a new location (in this case a git repository), fixed it once.
Things I tried that didn't work (but have worked for others):
Restart Xcode
Restart machine (this worked once before, not this time)
Create a new storyboard.
Create a new subclass (not just rename it).
Create a new project via Apple's single view template.
Cleaning the project
Deleting derived data
Reindex the project
Remove localization on the storyboard file.
Things I tried that didn't work:
Naming the subclass according to Apple's conventions (e.g. instead of View use ABCTestView).
Import the .h of the class in the .h and .m of the view controller.
Try on another version of Xcode, which is already installed (beta 6.2).
Related discussions:
https://discussions.apple.com/thread/3054574?start=15&tstart=0
Storyboard uiviewcontroller, 'custom class' not showing in drop down
This wasn't your specific situation but I was in a similar "rip my hair out" moment. When creating custom controller classes and using the interface builder, you must make sure to click the yellow button at the top of the view you're working with (the view controller button). Otherwise the custom ViewController class won't show up in the custom class drop down menu within the identity inspector.
One thing that worked for me after inexplicably seeing the issue where the "Designables" row would not appear in the Custom Class section of the Identity Inspector:
Before (not functioning: Designables did not appear and Interface Builder did not render my class):
IB_DESIGNABLE
#class MyCustomClass;
#interface MyCustomView : UIView
After (functioning: Designables did appear and Interface Builder did render my class):
#class MyCustomClass;
IB_DESIGNABLE #interface MyCustomView : UIView
So it appears that Xcode is very sensitive to the order of things.
This is what worked for me:
I somehow lost the view reference, so all i did was to drag from a little circle "New Referencing Outlet" to the main view of the .xib, and BOOM!
Here are some possible solutions:
When using the IB drop down to choose a custom class, none of the custom classes appear.
Manually type the name of your custom class instead of trying to find it in the dropdown. Sometimes IB will autocomplete the name of the class as you type, especially if you follow Apple's conventions, i.e. YourView as a subclass of NSView.
IB_DESIGNABLE and IBInspectable do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined as IB_DESIGNABLE.
If the view does not begin as a Custom View either dragged from the Object library or created from Editor > Embed In > ..., for some reason changing the Custom Class in the Identity inspector doesn't make a difference. To fix this, right-click the .xib and choose Open As > Source Code. Search for the view you want to fix (giving your view a label that is easily identifiable in IB will make this easier). You will find an entry like this:
<view ... customClass="YourView">
...
</view>
Change view to customView so that the entry resembles:
<customView ... customClass="YourView">
...
</customView>
then right-click the .xib again and choose Open As > Interface Builder XIB Document and you should now see a Designables entry under Custom Class in the Identity inspector of IB and Debug Selected Views will be available under the Editor menu.
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
Doesn't sound like your exact problem, but on a dual-monitor/multi-monitor setup, if IB is on a different monitor from the source code window, go to Apple menu > System Preferences... > Mission Control and uncheck Displays have separate Spaces. This may have some visual side-effects (like window drop-shadows bleeding into other monitors) but it will fix the problem of ctrl-dragging onto a separate monitor.

Xcode Create .xib File For Already Created Files

I have a few files (.h and .m) that do not have a corresponding .xib or storyboard file connected to them. I know how to create a new .xib file but how would I create one and have it connect to the other files that correspond to it? Thank you so much!
Simply creating it and including it in the target will suffice.
The default implementation of loadView will look for a NIB/XIB with the same name as the class (take a look at the UIViewController documentation for more information on that process.)
If your class has bindings, just name them correctly and add IBOutlet before them in the header file to make them visible in IB.
If you have overridden your initializer, you may need to incorporate some calls to super. The easiest way to see exactly what would be to create another view controller and add a XIB at the same time using Xcode's interface, and take a look at what is created. This isn't likely, though, as most calls to super end up going through the right path in the long run.
Post specifics if you have difficulty.
First add new file as user interface and select view. Then give name whatever you want. then in that xib file's "File's Owner" set the class for what you want xib file.
then bind the view with "File's owner"'s view. That shit.. Now you can access that class by initWithNibName method and in that method give nib name of that newly created xib file. may be it works for you.

xcode 5 in storyboard impossible to connect view controller with .h and .m

I have the Problem that i can`t connect my view controller with a objective-c class.
I have searched if someone has the some problems but i did not find anyone and no thread had a solution for my Problem.
I know how to set the connection with the .h and .m file but when i create a new objective-c class this class is not listed under the classes so i can not connect my view with it in the storyboard. i create the class with xib unchecked so i do not know where the mistake could be.
You need to make sure the UIViewController you're creating is of the same class as your class in the code first. Third tab on the right pane in the Interface builder, while the ViewController is selected in the items list.
The only way for me to solve it was to create a new Project, and then everything in this new project worked.

Xcode 4.3: how to create a nib linked to a view controller

Sorry, I'm quite new with xcode with a quite big project.
I upgrade xcode to 4.3.
I have a project (that doesn't use storyboard) and I need to add a view controller with a nib file.
Before upgrading I did File --> Ne File --> Cocoa Objective-C subclass and xcode created for me the m/h and their nib file.
Now that that option is disappear, how can I add a view controller?
I created the Objective-C class and, separately, a nib file, but how can I link the H/m files to the nib??
How can the m file call is nib??
Please can you help me? The project is real big and I can rewrite the code with the storyboard option!
Thanks
When editing your XIB, go to the Identity Inspector (it's the third button show in the following image). Then where it says Class, choose the controller you want to associate with the XIB.

How can i make a .XIB from .h and .m files?

I'm working on an existing project which I basically need to create a .XIB
so I can then put in UIToolbar and UIButtons ect.
On the App already it has a Tab bar but has been inputted through code and not the Interface Builder.
I would appreciate any guidance on my problem.
Kind Regards.
There is no automatic code that does this for you. You'll need to look in the code, find all UIView instances that need to go into the nib and manually create it. Then you'll have to be sure to set the frame of each of them to the same positioning as what is defined in the code. Finally, you'll have to be sure to remove all of that from the code (once it is fully migrated to the nib). Finally, you'll have to be sure that the components are referenced only after the nib has fully loaded (which might not have been the case in the current code).
Why not keep the components in the code (and just use nibs for new views)?

Resources