i am new to Swift and i started to play around with ResearchKit.
I created a custom class, which is basically the model and i want to connect this with the (also custom ) viewController.
In the API i found this.
To present an active step in your app, it’s likely that you will subclass ORKActiveStep and ORKActiveStepViewController to present custom UI and custom prompts. For example subclasses, see ORKSpatialSpanMemoryStep or ORKFitnessStep. Active steps may also need ORKResult subclasses to record their results if these don’t come purely from recorders.
My problem is :
How do i tell/assign the class the viewcontroller ?
There is no "setViewController" method.
It's the ORKTaskViewController that instantiates the correct step view controller for your step, when it finds the step in the task. It has two ways to do this.
The first is to consult your step's + (Class)stepViewControllerClass class method. If you write a custom step class, override this class method to specify what class of step view controller the task view controller should instantiate by default for that type of step.
The second is to implement the task view controller delegate's -taskViewController:viewControllerForStep: method, and instantiate a step view controller of the correct type when your step is encountered by the task view controller. If you return a non-nil value from this method, it overrides the default outlined above.
Related
we wanted to present a custom SFSafariViewController to present the reCAPTCHA, it was given in the firebase docs to create a custom class that conforms to the FIRAuthUIDelegate protocol, and pass it to verifyPhoneNumber:UIDelegate:completion:.
I created a custom class that conforms to the protocol but the protocol needs us to pass a viewcontroller to it, but none of the details required to create that viewcontroller or any details or example as to how to use a custom viewcontroller is not given anywhere.
It's been a while since this was asked but I had to attempt to do this over the last few days and couldn't find the answer in the documentation either.
The view controller passed to the protocol functions is not one that you can create yourself as it's provided by the Firebase SDK and it's some implementation of SFSafariViewController.
As long as you have set the delegate object on the call itself than the SDK will trigger the delegate object methods directly providing the View Controller.
The delegate is expected to be able to manage the layout of the controller and its own views so it will need some reference to a parent UIViewController.
You are limited to the customisation available for this class and its own views. I assume you could start manipulating the view hierarchy in the controller itself but as this was provided to me by Firebase I settled for just adding this on a view container in the parent.
You can add and remove the controller and view as a child controller as normal.
I'm trying to simplify my life by dividing chunk of related code into different classes.
But I encounter a problem: changing the ViewController property (like UITextField.text, etc.) from those classes.
I have tried creating protocol, but that was really messy so I want to find a new way to do this.
So, is there a simple way to change ViewController property directly from external classes? I'm using Swift 3 btw.
Thank y'all for helping.
If the object from where you want to change your label is a child object owned or presented by the controller, than you need to use delegation to comunicate back with the controller. You declare a protocol in that object from where you want to change the controller's label, and declare a weak property of that protocol type called delegate. When the controller creates that object you will set that object's delegate property to the controller itself (If that object is ownee by the controller, declaring the property weak you will not create a retain cycle). In the controller you implement the method declared in the protocol and in the implementation you can change the label.
The other case when the controller is owned or presented by the object from where you wanna change the label, in yhis case you just need a public method to do that.
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)
I have a view controller which gets an NSObject conforming to a protocol and then displays a view with the object's properties.
The question : How can my controller know that a property of this object has been modified and then refresh the view ?
Thanks a lot
Thierry
There are three ways of doing this:
Have the object call a method in the controller in response to an event e.g. a user clicking the button. This is usually done using an IBAction.
Set the controller to be the delegate of object e.g. a UIWebView sends a message to its delegate when it finishes loading a page.
Use a notification. The object generates the notification and then one or more objects (including the controller) registers to listen for the notification. This is usually not used with interface elements although it can be.
I can't tell you more without more detail about the specifics of your project.
Your viewcontroller should conform to your .
In your model, all your set methods should trigger appropriate functions you define in your modelchangedprotocol.
This OO design pattern is also known as "Observer" design pattern.
I am developing a special type of view controller for an iPhone component library.
I have got the who view controller working well, but I need to change it so that it works in one of two ways:
Either it is an abstract class which you must subclass and provider the implementation for a specific method which the controller will call whenever it needs its data.
Or it needs to be a useable class which has a property which is a selector... when you set the selector it specifies the method which should be called to collect the data.
I would like to know how I can implement either of these and which you would recommend
The standard way of doing this in Objective-C and the iPhone is through delegation.
Normally you provide a property in your view controller called delegate that is typed for a particular protocol you create. Then who ever is using your view controller will set the delegate property with their delegate for your view controller. You can then call the methods in your protocol on their delegate.
See the answer at this SO question for a full example.
Also read the Cocoa Fundamentals Guide for information on what delegates are and why they are used in Cocoa. There is also an example there of how to create delegates for your own custom classes.