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 6 years ago.
Improve this question
There is a method in UITextFieldDelegate
textField(_:shouldChangeCharactersInRange:replacementString:)
Which allows me to do it. But I want custom text field handle this automatically to update its state without delegate and I don't want to use delegate internally as it can be overridden. How should I do this?
For example there is a method - becomeFirstResponder which I override to show/hide validation error when text field resigns from being first responder, but there seems to be nothing for handling text property changes, or was I inattentive?
You could use UITextFieldTextDidChangeNotification.
Or you could subclass so you can be your own delegate and also forward delegate calls to another delegate which is added (so your internal delegate is a proxy for the real delegate, handling the call and then forwarding it).
Related
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.
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 2 years ago.
Improve this question
I have a custom UIView which has a press method. This is a subview added to the main Google mapView. When this method is called, I would like to either call a function or set a global variable in the main ViewController.
Any feedback would be appreciated.
Built-in NotificationCenter API to broadcast notifications whenever the press method is called.
let nofitication = NotificationCenter.default
nofitication.post(name: Notification.Name("pressMethodCalled"), object: nil)
Register the notification:
nofitication.addObserver(self, selector: #selector(your_method_name), name: Notification.Name("pressMethodCalled"), object: nil)
Delegates: One to One. Read more here - https://medium.com/#jamesrochabrun/implementing-delegates-in-swift-step-by-step-d3211cbac3ef
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.
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 6 years ago.
Improve this question
I created a navigation controller and put 2 view controllers linked to it. One is called FirstLaunchVC and the other is FirstLaunchVC2, I want the user to put his name in the text field nameTxtField and when he clicks on the continueBtn it should lead to the other. In this second view (FirstLaunchVC2) there is a label called nameGreetings which will show the name of the user as a greeting with prepareForSegue, the thing is that it's crashing, saying that there are breakpoints on the line of the performSegueWithIdentifier and on the line where I write "nextVC.nameGreetings.text = "(str) etc etc". I have no clue why, can anyone help me with that? Btw, I've already checked the identifier and it's correct.
Is nameGreetings an IBOutlet? You cannot set the IBOutlet controls for the destination view controller in prepareForSegue of the originating view controller because while the destination view controller has been instantiated, its views and IBOutlet references have not. The prepareForSegue should feel free to update String properties of the destination, but not its IBOutlet references.
So updating of name is fine, but the nameGreetings should not be set in prepareForSegue, but rather that should be deferred until the the viewDidLoad of that FirstLaunchVC2.
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.