My ViewController's view contains:
Custom UIView with UITextField;
Custom UIView, which contains another custom UIViews (with UIButton) inside UIStackView .
So when UITextField is first responder - UIButton target (.touchUpInside) won't work. And it's all ok when UITextField is not first responder.
Related
I added UIView in storyboard & make it as UIControl's subview. This view is inside UITableViewCell. Now I want to add touch up inside action for UIControl. I have added below code:
[cell.conditionControl addTarget:self action:#selector(btnConditionClick:) forControlEvents:UIControlEventTouchUpInside];
But this code is not working & not receiving any events.
I also disable userInteractionEnabled flag for UIView's Subview.
I want to replace the default keyboard of a UITextField with a custom keyboard. So I created a new subclass of a UIViewController with a xib-file (the other way like creating both files seperately and setting the File's Owner doesn't work either).
Then I added a button to the KeyboardView and connected it to an IBAction. After that I set the textfields inputView to the new view like this:
override func viewDidLoad() {
let keyboardVC = KeyboardViewController()
textField.inputView = keyboardVC.view
keyboardVC.view.autoresizingMask = .FlexibleHeight
keyboardVC.delegate = textField
}
It's working and the custom keyboard shows up, but if I touch the button, the IBAction is not called. What's the problem in my setup? (I checked some examples and they all do it the same way).
UPDATE:
I now removed the ViewController and subclassed the UIView. Now the actions are working. Why isn't it working with a ViewController?
Since no one holds the UIViewController- there is no reference to it after the viewDidLoad() ended, it is released from the memory.
When the button is pressed, the view controller that should response to the action is not exist -> you are holding only the view of the view controller as the textField.inputView.
I have a rightView on UITextField with the mode UITextFieldViewModeUnlessEditing, so it should disappear when we are editing the textfield.
But now when I start editing the textfield programatically when you press the rightView (an edit button) the rightView does not disappear immediately. It only disappears when I start typing something.
So why does editing for a UITextField only start on typing and not on becoming first responder? How do I fix this?
Add the < UITextFieldDelegate > to your interface.
Then set the delegate or your textfield to self (either in IB or) for example in viewDidLoad:
self.theTextField.delegate = self;
Add this method to your .m :
-(void)textFieldDidBeginEditing:(UITextField *)textField{
// Whatever is supposed to happen when you begin to edit the textfield happens now
}
I have created a UITableViewController with a UITableView and static UITableViewCells.
How can I change the Accessory View to a custom Image within a UIImageView?
I know how to change the Accessory View generally:
UIImage *accessor = [UIImage imageNamed:#"imageName"];
[somecell setAccessoryView:[[UIImageView alloc] initWithImage: accessor]];
The solution:
Create an IBOutlet for each UITableViewCell which should have a custom accessory view and connect the IBOutlet to the UITableViewCell in the storyboard. After that you can set the accessory view like above.
I found a better solution:
Drag a view (for example a instance of UISwitch) into UITableViewController in storyboard
Selet the cell on which you want to add a custom accessory view. Then open the Connections inspector, drag the accessoryView in section Outlets to the view that you created in step 1.
Now run the app, see a custom accessory view appearing in a static UITableViewCell. Of course you can create another IBOutlet between the UISwitch and controller so that you could get the reference of it, or create an IBAction for receiving action when user change the value of UISwitch.
Add a custom UIButton in the storyboard and set the image you want to it
I tried to create a subclass of UILabel called EditableLabel and implemented canBecomeFirstResponder, isUserInteractionEnabled, both of those two methods return YES, in the meantime, I over-write inputView and inputAccessoryView and make them writable.
My problem is that when I tap on the label, the inputView can't be shown on the screen. Anybody know how to implement the subclass of UILabel view and let the inputView shown?
Thank you very much.
Why not just use a UITextField and set its borderStyle to UITextBorderStyleNone?