Added class unable to be selected for a new XIB - class

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
{
...
}

Related

Why doesn't Interface Builder see my class in the static framework?

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.

What "UIViewController" class really does?

I was working in the ViewController.swift and noticed that when I open it, it declares a UIViewController class. I was wondering if that is a new class or an already declared class that we can add code to.
I was wondering if that is a new class or an already declared class that we can add code to.
UIViewController is a class defined in the UIKit framework. It's the class that's used as the base class for all other view controllers in iOS applications, so it provides the behaviors that are expected of any view controller as well as a number of methods that are meant to be overridden. The usual way to "add code" is to create your own subclass of UIViewController, which is exactly what you're doing in the ViewController.swift file.
You're going to run across many classes that have the UI prefix, and you can look up any of them in the documentation that comes with Xcode.
UIViewController is not the class that you can add code to. But ViewController is default class that has UIViewController as a parent.
ViewController class is already connected with storyboard view controller when you create your project by default. So you can add some code to ViewController class and connect your UI controls (buttons, labels and so on) with you ViewController class and add some functionality to it.
So yes, you can add some code to it and see what happens when you build and run the simulator.
Its a class that manages view controller functions.
For example, "YourClass:UIViewController" means that You extend from UIViewControllerClass, so You are able to use all the functions from mother class, but also add new in "YourClass".

Best Way to Add Object Via Other Class?

In my iPhone app, I have a custom UIViewController class setup which adds some UIImageViews and things.
How can I access this class via my main UIViewController and, for example, call a method from that outside class and have it add those UIImageViews to the view?
Make property and public methods, after that you can call them in target viewcontroller.
p.s. But I never used this approach because it breaks controller's logic. Instead of I usually use some managers which has all required methods. (DBManager, NetworkManager, etc)

Interface Builder wont let me rename the "View" class name to existing Class

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.

Objective-C Interface Builder don't see renamed class

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.