How to connect a Text View with a UITextField outlet , in iOS? - 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)

Related

Xcode 7.3 UITextField is no longer a valid event source

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)

iOS presentViewController freezed when storyboard has a TextView with one word only

I am having this weird problem in my iOS 9 device, the app just freezed when I try to presentViewController to a ViewController designed in storyboard. And the ViewController happens to have a UITextView with single word as the content: Name
How I fixed it:
After I changed the Name to Name : (notice the space there), it runs fine now.
This is not really a question, rather than a reminder to those having this weird problem.
I got this problem and I removed text from Interface file and put it in programmatically in viewDidLoad method.Sometimes space also don't work so better put text programmatically and you can add without space as well.

Storyboard: assign IBOutlet for multiple object per size class

Since Apple introduce Size Classes, whew, routine work might gone, I thought. Going further, realised it's not so easy, so comfortable like it seemed to be.
My real purposes a bit different by I've set-up test project for illustration:
I have one storyboard, one IBOutlet for UIButton and decided this button to look different for different Size Classes
For that I created two buttons:
iPhone button (installed for wChC)
iPad button (installed for wRhR)
Problem:
each time when I try to connect any of those buttons to IBOutlet button - it always works for one button and erases connection to another.
I want those two buttons to be actually one button but with different layout for iPhone, iPad.
Previously, having two storyboards it haven't been an issue.
How to achieve this within one storyboard?
If you designed separately for iPhone/iPad means, you can't have same IBOutlet connection for both Button. Better to create separate IBOutlet for iPhone/iPad.
Use Any|Any in storyboard for support both iPhone/iPad design with single IBOutlet.

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.

Using UIScrollview to display .xib as different pages?

I think im missing something fundamental here because everyone seems to be able to do this simple task. Im trying to create an app that is very similar in presentation to the iPhone home screen (paging). I plan to have several pages that each have their own unique content. My understanding is that I can use UIScrollview to display and animate these pages/xib's but I have tried what seems like everything and am frustrated by the lack of instructions for newbs like me.
What I understand so far:
Declare IBOutlet UIScrollView *scroller
Set options in .m or in scrollview object via IB
connect fileowner of main .xib to *scroller
connect fileowner of main .xib to delegate
then somehow call in the other xib to load as the pages for the scrollview.
One thing i have found is that most of the tutorials and source codes i get are outdated or look different. Im using xcode 4.2. ANY HELP is greatly appreciated. Thanks!
I'm also a newbie so may be I don't understand your problem exactly but if you want to represent your scroll view in pages you should enable paging for it:
yourCoolScrollView.pagingEnabled = YES;

Resources