I've renamed a UITableViewController class in Xcode, which was used as a parent class in a XIB. The Interface Builder still uses the old name for that class and it compiles and works fine. Interface Builder doesn't see the new name of the class and when I try to type in manually, it compiles and gives me an exception at the runtime: "Unknown class ... in Interface Builder file."
Is there a way to update the class name in the Interface Builder?
Thanks
Have you tried to select "File -> Reload All Class Files" in Interface Builder? Maybe that should work!
you can try...
Clean and rebuild project
delete XIB from project and create new one with new class
delete class and XIB both from project (reference), copy them somewhere else and Add new file with XIB user interface in your project and copy everything from old class file to new class file...
One out of these three should work...
Close your Interface Builder completely.
And Open that XIB from XCode.
Then it will display your renamed class.
I sometimes have problems with IB not noticing changes in class files.
What I do then is I drag the .h file from XCode to the window with .xib file inside of Interface Builder. That updates the class definition.
You can always reopen Interface Builder, but the above solution is quicker.
Related
There is a Cocoa framework project called MyFramework with Mach-O Type set to Static Library that features MyView.swift with a following declaration:
open class MyView: UIView { /* ... */ }
In the meantime, another project called MyApp statically links against the static framework MyFramework. Additionally, Main.storyboard of MyApp has a scene in which there is a view, whose custom class is set to MyView and module is set to MyFramework.
Whenever the view controller that backs this scene is instantiated, the view behaves as a default UIView and I see the message in console:
2018-06-23 18:22:29.114096+0700 MyApp[2318:415810] Unknown class _TtC15MyFramework15MyView in Interface Builder file.
Then, I add to MyApp's target a MyNewView.swift with the following declaration:
class MyNewView: MyView { }
Without changing anything in the Main.storyboard, I launch the app, the MyView class gets instantiated, it behaves as supposed and the message doesn't appear.
Question #1: why does this happen? Is the type stripped or not registered with the Objective-C runtime if it's not directly imported or referenced from anywhere in code? Or maybe is it somehow lazily loaded?
Question #2: what can I do with it so that I don't need to apply such workarounds?
Update: I restarted the Xcode and the issue did not persist, yet still, the interface builder doesn't suggest MyFramework as a module while typing in the Module field in view's identity properties, and the #IBInspectables of MyView don't get parsed, don't show up in the interface builder, in the view's attributes.
I added a new class to solution (iOS), together with XIB and its designer.cs.
Problem is I cannot select this newly created class (NewAccountView.cs) in the XIB NewAccountView.xib properties (see the drop down list does not include my added class NewAccountView.cs.)
I am new to Xamarin and I am sure I am missing a crucial step here. Pls help.
Did you use the View or the View Controller template?
If you used the View template, then only the .xib is created and you would have had to create the View class separately, in which case it probably did not automatically add the class inheritance and the Register attribute to your class. Make sure your NewAccountView inherits from UIView (or some subclass of UIView as appropriate) and also that you register it. E.g.:
using Foundation;
using UIKit;
...
[Register("NewAccountView")]
public class NewAccountView : UIView
{
...
}
i would just want to ask why i cannot create an iboutlet (e.g. UITableView). I copied a nib file, the .h and .m file from my different project(since I need them). After that, I renamed the .h, .m and the nib file. Then when I am going to add or connect IBOutlets to it, I can't. Why? Does someone know how to fix it? thanks a lot.
This is because you need to provide a new class name which the xib refers to (as you said you renamed it)
Maybe You forgot change class name in .xib file.
Try following steps for renaming .h,.m and xib files. This will be Helpful for you.
1) Go to the header file eg. MyViewController.h.
2) Right click on your class name eg. Right click on MyViewController.
3) Select Refactor -> Rename.
4) Write New Name eg. MyViewController1.
5) Preview and Save.
This will rename your Old class name with New Class name from everywhere.
And Also check File Owner's Custom class property under Identity Inspector Section is the same as New Class name
I'm following a tutorial from the book "Beginning iPhone Development", chapter 12.
I have a class called QuartzFunView with .h and .m files.
If I double click on my blaViewController.xib file, then click on "View" and in the Identity Inspector try to change the Class (Class identity) from UIView to QuartzFunView, my computer just beeps and stays as UIView. I can change the class to all the UI.. classes and any other random letter combination I choose, just not QuartzFunView. What am I doing wrong?
I am writing this as answer because people do not need to read comment for answer
That existing class QuartzFunView must be a sub class of UIView class to be able to set as identifier of any UIView in xib file.
I am new to iPhone development so I have been working through some tutorials. What I don't understand is how xib fit into the work flow.
In a tutorial, one of the instruction is to create a new UIViewController subclass with "XIB for User Interface" selected. On my first try, I neglected to check that option and I thought may be I can just create the xib in Interface Builder but that didn't work. ( I created the xib using Cocoa Touch View Template, with the same name as the UIViewController and saved it the into project directory so it was added to the project.) I even changed the Class Identify for the File's Owner and hooked up the view outlet (the two differences I noticed when I inspected the xib generated from Xcode.)
So what are the differences between Xcode generated .xib (from UIViewController Template) and the IB .xib template?
XIB files created as part of the New File flow in Xcode have their File's Owner class pre-set, as well as certain outlets (view) already connected. Otherwise, there's not much difference.
The XIB File is basicly an uncompile NIB File, XIBs can always be edited in Xcode (unless they are outdated or corrupt) but most NIBs are compressed (flat) and are unopenable. However the older NIBs are bundles containing some source/archived including designable.nib which is often just the renamed XIB File and a keyedobjects.nib which is an other compiled NIB
NIB = Nxt Interface Builder
XIB = Xml Interface Builder
Although the new archived NIB files are unopenable to most applications including Xcode, they can still potentially be unarchived. I found this freeware application called NibUnlocker On The CharlesSoft Website which can potentially disassemble a compressed Nib file and exports it as an XIB document. This application is still fairly buggy but it is sometimes very accurate based on the Nibs contents.
(NibUnlocker is a very inaccurate name, Nibs are not locked they are archived)
Click to Download Nib Unlocker
If You wish to know a bit more you can read some additional information I have provided below in regards to the NIB and XIB Formats:
Nxt Interface Builder Anatomy:
Archived NIBs
A Compressed NIB file is complicated file to analyse but this is not impossible. The structure of these files are based off of a compacted property list (begins with "bplist00") and some of its contents are archived through NSKeyedArchiver. Since a NIB is formatted as a property list, This allows a small hack: if you actually change the extension of a Nib to .plist, eg. ArchivedNib.nib to ArchivedNib.plist You will actually be able to open it in Xcode viewing it as a Property List. When you view a Nib as a property list you will probably get a few base properties such as $version, $objects, $archiver and $top.
Useful Notes
A CFKeyedArchiverUID object is actually a redirector, in the {value = xx}, the value is an offset for a item in the $objects array from the start of the array. eg. <CFKeyedArchiverUID 0x60800002bc20 [0x7fffef6b8c30]>{value = 29}, value = 29, the result would be the 29th item in the $object's array. In Objective C you can retrieve this value from an NSArray with this method :
+ (NSUInteger)valueForKeyedArchiverUID:(id)keyedArchiverUID {
void *uid = (__bridge void*)keyedArchiverUID;
NSUInteger *valuePtr = uid+16;
return *valuePtr;}
like if this helped ;-)
I'm not sure I'm following your question. When you created a xib file in Xcode, attempting to edit the xib file will bring up IB. So effectively you are using IB to edit the xib file in Xcode. I never tried creating a "stand-alone" xib file in IB and then hook it up to a project in xcode.
The only reason such an approach may not work is that when you create the xib file within the context of a project, there are associations created (such as "mainnib file base name" attribute in the plist) which will not be automatically generated when you attempt to use a standalone xib file with the xcode project.
It sounds like you configured the view xib properly, by setting the View outlet and configuring the custom class for File's Owner, but perhaps the problem was with the UIViewController subclass.
If your view controller subclass had implemented the -[UIViewController loadView] method directly, it'd prevent the NIB from loading. In the default implementation, the UIViewController will load the NIB file with the same name as the view controller. If you override this method to initialize the view a different way (e.g. completely programmatically), the default implementation that loads the NIB won't run.
Deleting an override of the -[UIViewController loadView] method in your subclass, or ensuring the names match, might resolve any discrepancies.
XIBs are XML. Diff them and find out for yourself.