What is the difference between UIViewController and UIInputViewController ios swift [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Here I'am working on CustomKeyboardExtension. In my extensible .swift class file the class definition starts with UIInputViewController
class KeyboardViewController: UIInputViewController {
#IBOutlet var nextKeyboardButton: UIButton!
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
}
}
So what is the difference between UIViewController and UIInputViewController.

UIInputViewController is a subclass of UIViewController. It has all the same functionality as UIViewController but also includes some extra logic. It is specifically designed for creating custom keyboards.
What all features are added into UIInputViewController is best seen in official documentation.

Related

Why can't you rename the body property? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
In swiftUI, in order to conform to the View protocol, the conforming struct has to implement the body property (specifically, its getter, since body property is read-only).
Can I change the name of body property to something else, say presentation?
struct ContentView: View {
var presentation: some View {
Button("Hello SwiftUI!") {
}
}
}
This doesn't work. I get 'Type 'ContentView' does not conform to protocol 'View'.
In UIKit, when conforming to the UIApplicationDelegate protocol, I was able to change the name of the UIWindow variable. The documentation has the name 'window', but when conforming, I changed it to mainWindow and things worked.
Why can't I change the name of body property of a swiftUI view? Am I missing something?
Can I change the name of body property to something else
No. A protocol's requirements are required. To conform, you must obey them to the letter.
when conforming to the UIApplicationDelegate protocol, I was able to change the name of the UIWindow variable
That variable isn't a requirement. Note the marking optional on the page you yourself linked to.

How to not repeat code in Swift for attributes of button? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am new to IOS Development. I am creating an app with a lot of buttons. How do I give the same attributes to all the buttons with help of a class?
Your answer really isn't ideal for stackoverflow since it's not a direct problem your looking for help with, but instead a question of best practice. Check the code of conduct again.
However you can do the following:
(If you need those buttons to be instanced/complete right away)
a) Create a private static function in your class which builds your buttons with the attributes, and gives them the text and selector you pass via parameters.
b) Create a private static function which only applies the attributes you require
(If you just want to apply the same style)
a) Create a private function in your class which stylises all buttons upon viewDidLoad
There are a few things you could try:
1 - You could try and create a subclass of UIButton with the common styling code, and use that custom button in your program instead of UIButton.
2 - You can extend UIButton to have a styling category function, then call that function from viewDidLoad() in your view controller or awakeFromNib() in your view.
3 - You could use the appearance protocol to style some aspects of the button (though it can be a bit limiting).
The approach you choose to do and how you choose to develop is something you need to decide as a developer.

Cleaning of ImageView [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I need to clean ImageView. I have some figures there.
#IBOutlet weak var imageView: UIImageView!
I tried using
imageView.image = nil
but it doesn't work. How can I clean imageView?
ARC counts the strong references to an object. If there is none, that object is deallocated.
If your the image view isn't strongly referenced from anywhere else, then removing it from the view hierarchy should do the job:
imageView.removeFromSuperview()

How to make one IBAction that does the same action to two buttons when the first one is from a custom cell and the other one is from storyboard [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
This is from the custom cell:
This is from the Storyboard:
Anyone have any idea how to make these two buttons do the exact same action? Is it possible to make multiple buttons do one action?
I usually keep the backing UIViews and UIViewControllers very thin in my applications and I create classes that do the actual heavy lifting. This makes for cleaner code and easier reuse.
class Player {
static func play() { // Static makes it easier to call from every class, assuming you only play one song at a time
// play logic goes here
}
}
class MyView: UIView {
#IBAction func play() { // connect in IB in your .xib
Player.play()
}
}
class MyViewController: UIViewController {
#IBAction func play() { // connect in IB in your storyboard
Player.play()
}
}
You need two IBAction methods in separate classes (for cell and for view controller). If you want to minimize repeating code try to make a special class with this functionality and then call its method in two IBAction methods.
Also you can take a look at Command design pattern for this purpose.

How to assign a set of methods to UITextFieldDelegate [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to know how to fire a method when a particular text box is edited.
For example, it is explained here how to assign a certain format to a textbox, using a number of functions. However, I don't know where to copy-paste these functions. In the explanation it says to use UITextFieldDelegate, but I don't know where it is.
I have a AppDelegate class, a ViewController class (including its xib), and a UITextField in the xib. I want the code to work for this UITextField.
Add those methods in your ViewController.m class
and then in your viewDidLoad method of ViewController.m Class
[yourTextField addTarget:yourTextFieldDelegate
action:#selector(reformatAsCardNumber:)
forControlEvents:UIControlEventEditingChanged];
set reformatCardNumber: to be called whenever the text field fires a UIControlEventEditingChanged event
also add delegete in Viewcontroller.h file
and Thats Done.

Resources