Using a ViewController with a dot in its name through storyboards - swift

Is it possible to reference a UIViewController with a dot in its name through a storyboard?
Login.ViewController for example?
class Login {
class ViewController: UIViewController {}
}

Interface Builder is not aware of nested classes that are available in Swift, so you cannot set a nested view controller class as the class for a view controller scene in a storyboard.
Apple may address this in the future or you could consider posting a feature request

Related

Added class unable to be selected for a new XIB

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

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".

I can't get my head round - (void)playInputClick;

I have an inputAccessoryView for a UITextField set up, which is loaded from a XIB when needed (in the exact same way as Apple's KeyboardAccessory example).
I'm trying to get the buttons on it to click when pressed using the playInputClick function but I can't work out how. The Apple documentation says that I need to add add a delegate method to the view, but the view was created purely in interface builder so I don't see how I can do this.
Does anyone know how to make this work? There seems to be no example code of this method being used anywhere on the internet.
I've been having the same problem and finally figured it out.
If you implement the protocol in a UIViewController it does not work. It needs to be implemented in a UIView subclass.
So to get it working, I created a view in interface builder with a view controller. Then I added another class which is a subclass of UIView. This class implements the UIInputViewAudioFeedback protocol. Then in interface builder I went to the Identity inspector of my view and changed the class to my UIView subclass which implements the UIInputViewAudioFeedback protocol. And the keyboard click sound is now working.
My view controller is still calling the [[UIDevice currentDevice] playInputClick], all I did was move the code for the UIInputViewAudioFeedback protocol into a UIView Subclass and set my views class to my UIView sublass.
Assuming you are trying to do this in an inputAccessoryView:
In the .h file, indicate that you implement the UIInputViewAudioFeedback
#interface YourAcessoryView : UIView <UIInputViewAudioFeedback>
In the .m file, add this method to satisfy the protocol
- (BOOL)enableInputClicksWhenVisible {
return YES;
}
When a button is pressed, do something like:
- (void)buttonPressed:(UIButton*)sender
{
[[UIDevice currentDevice] playInputClick];
// do more stuff
}
You need to implement a view controller class, and in the interface builder assign the files'owner as this class. Connect the view controller's view to your view.
Once you have done that you can implement the delegate in the view controller.
Its pretty simple and straight forward. Basically your view will be a member of a view controller class.

how to call add a view from NSObject class

I am working on an app where i am doing some code in a class which is derived from NSObject and in this class i want to call another class which is a UIView type class and add it above current view or if possible over window. Can someone suggest me how will i do it as i cannot call [self.view addsubview:view] from a NSObject type class?
Also i can not move from my current class as here i am doing act(uploading with progress view) which will take time. so i have to add subview over my current view from this class only.
and yes i have to remove that uiview also later on when uploading completes.
Thanks in advance
Sounds like you want to add a view to the window:
[[UIApplication sharedApplication].keyWindow addSubView:myView];
How about placing your NSObject class inside a UIView, and then keeping a variable that references that view (eg masterView). You could hook that up in Interface Builder to a view that contains the NSObject, or if you're not using IB, create a UIView before instantiating your NSObject-derived class inside it, and pass a reference to the NSObject class which points to the master UIView.
Then, when you want to add a new subview to the screen, call
[masterView addSubview:anotherView];

Event name when IBOutlet is assigned in the controller

I would like to run some logic in my Controller class once all IBOutlets get assigned. What method do I need to override in the Controller class to receive this event?
Thanks,
Rui
The -(void)awakeFromNib method is called after the outlets are connected. There's a good article on it at Cocoa is my Girlfriend