Xcode 7.3 UITextField is no longer a valid event source - ios

After upgrading to Xcode 7.3 it seems as if UITextfields can longer send events in storyboards or nib files. In previous versions you could control drag from the storyboard/nib to a source file and create an action. In Xcode 7.3 you can only control drag to a source file and create outlets. Right clicking on projects that previously used "Send Events" in Xcode now show a warning triangle with the text described in the title and attached picture.
Does anyone have any idea if this will be added back, or reasons for its deprecation? I've switched to programmatically checking the events in the mean while.
Thank you.

Do you figured out it? Got same problem, but with UIButton. The case is when you make an extension to UIButton (UITextField in your case) that adopts control to some protocol it loses ability to connect actions from storyboard. Check this out: https://openradar.appspot.com/30001713

The problem is somehow with the Storyboard, and not it's functionality.
You can still make it to work with this work-around:
Use subclasses, let's say class TextField: UITextField { } and add all your extensions to TextField.
In storyboard, first set your item's class as UITextField, and when you're done, set it's class as TextField. It will show that nasty error, but it will forward all events to your ViewController.
Update:
If it's possible for your use-case, extend UIControl and use UITextField or UIButton as they are. Turns out, Storyboard will not get mad when you extend UIControl to some protocols. (found it from this thread: https://forums.developer.apple.com/thread/25180)

Related

How can I properly handle touch events of a UIButton on top of another UIButton?

I'm trying to recreate the function of the clear button in UITextFields but with a UIButton and as such have a UIButton as a subview of another UIButton. I read somewhere that I need to have the superview handle the touch events of the subview.
The post that hinted at that was outdated and in obj-C so I'm looking for modern and swift version.
Placing a button on another button is a kind of bad implementation in spite of any requirements.
Hope you find out a right way to solve this problem.
Or you can just use a combination of enabling or disabling buttons according to the situation.

Can`t drag #IBOutlet from swift file to storyboard ViewController in Xcode 7.2

I use Xcode 7.2
I can use Control+drag to swift file to create a #IBOutlet
But I can't drag #IBOutlet in swift file to storyboard. Here I don't use any other key, just drag.
Actually when I moving mouse to the spot before #IBOutlet, nothing happened and when I trying to drag it a breakpoint added.
1.I`m sure I use the right Class name
2.My project is not in a strange path or name
don't use Control, only drag with mouse from circle icons.You can see in the picture below. Circle icons in red box
Changed Behavior
The behavior has changed in new versions of Xcode (I'm not certain but it might have been since 7+.). Older versions of the product might still have the gutter shortcut working.
Now you have to either open the Connections Inspector or right-click on the view controller in the Document Outline. Once open, drag from the defined IBOutlet to your UIView subclass (UIButton, UITextField, etc...)
Connections Inspector
Controller View
Official Guidance
Search your local help for: Interface Builder Connections Help: Creating an Outlet Connection. You will find these are the only methods that now work. The gutter shortcut does not work.
Nota Bene:
You can confirm this behavior and other changes to Xcode shortcuts by
choosing the following menu Help > Xcode Overview and
taking a look at Part V: Building a User Interface, section Connecting Objects In Code.

How to connect a Text View with a UITextField outlet , in iOS?

I have a problem that really drives me crazy.
A few months ago i started developing an iphone application , and i needed to have a multiline textField so that the user could write some comments. In the end , because at the time i couldnt find a solution , i found a solution how to use a Text View instead which is by default multiline. In my project it seems that i have connected this Text View with a UITextField outlet.
Now i am trying to make my app universal , so i created a new .xib file for the iPad version.
However it seems impossible to connect the Text View that i created with the UITextField Outlet that i was using with the iphone .xib.
I m really breaking my head here to remember how on earth i connected these two in the first place. I remember that i implemented some delegate methods to customize the Text View to work as a Text Field , and it seems that all the properties of my iPad Text View are the same with the ones of the iPhone version. However i cant connect it with the outlet.
Does anyone have any idea , what i am missing here?
It is imposible connect UITextView to UITextField. There is no solution or tweak using which you can alter UITextView to behave like UITextField. You better use some third party library and use it in your project. I am still surprised how you did it in your iPhone project. Can you please share some code how you did in iPhone for better understanding of what you are asking.
Outlets can be connected to the same types only and they are pointing to the object of the same types and they have 1-to-1 relationship, you can not connect one outlet to multiple objects either.
You might have named your UITextView as UITextView *textField or something , you need to Connect your UITextField outlet to the corresponding textField in your classes, you can not connect UITextField to UITextView.
It appears that after all is possible..
I tried the unthinkable and it worked..
I created a new outlet from my text View , a UITextView outlet and then... well i just renamed the UITextView to UITextField and works perfectly.. I connected both textViews (iPhone.xib and iPad.xib) in this outlet and it works.. (I connected them before renaming it to a UITextField outlet cause after that you cant connect them)

Xcode custom control via storyboard

I want to use a custom control in my project, specifically a horizontal picker view I found on cocoacontrols.com (http://cocoacontrols.com/platforms/ios/controls/cppickerview). I've been able to include it into my project, load data and it works very nicely.
The pickerView is setted up programatically on viewDidLoad but I'd really like to be able to use it via storyboards because I'm a using static tableView. I tried to add a UIView, set the class to the PickerView class and then set up the outlet. I builds without errors or warnings but the picker view does not appear. It only shows a white rectangle.
Anyone with experience in this? Is it possible at all or should I keep it programatically?
Thanks in advance!
Well, that's normal. CPPickerView does not seem to implement initWithCoder:... I only see an initWithFrame: in the source code, which obviously means you can only instantiate that custom UIView from code. Or you can change CPPickerView's implementation to support what you want. It's open source.

UIView with UIButtons not showing up prior to click or rotate

I've been banging my head with this issue for the last two days. Googled a lot but wasn't able to find the answer yet, so I decided to request some help here. Let's see if I get any luck.
I'm coding a reusable control that consists of an UIView with a variable number of customized UIButtons. I implemented initWithFrame:, initWithCoder: and drawRect: where the buttons (which are built prior to drawing) are actually added to the view. Everything is done programmatically since the UIButton content should be supplied when using the control, so there's no XIB for this UIView.
This UIView, let's call it CustomizableBarButton is then used in an UIViewController, let's call it MyTestViewController with a view on it, let's call it customizableBarButtonView.
MyTestViewController's GUI was set on IB where an UIView was tied to customizableBarButtonView (the class was matching accordingly).
MyTestViewController's is a pretty standard class except for the viewWillAppear: that initializes the buttons and passes them to the CustomizableBarButton along with some other options.
The issue is that everything works perfectly...except for the first time!
I mean, when I run the app on the simulator (I haven't tried it on the iPhone yet but I strongly believe that it's not an hardware issue) the MyTestViewController shows the customizableBarButtonView background but not the buttons. Now when you click on the place where a button should be all the buttons suddenly appear!
I'm puzzled since the CustomizablebarButton drawRect: runs before the strange "click n'appear" effect and the buttons are actually added to the subview.
Another hint that my help: if you don't click on the buttons (so you still got no buttons yet) but rotate the device they will also appear as if by magic!
It is probably something very simple but I'm missing it and I'm going nuts...
Can someone lend a hand on this, please?
Thanks in advance!
You said you're adding the buttons in drawRect:. Don't do that. You need to add the buttons in your init methods.

Resources