Not able to drag connect my UITextView to my custom UIView - uiview

I have been searching around for a while now, and I can't figure out if what I am doing is possible. I would think it is, but I am having no luck finding an example. I have a UIViewController, and nested inside that ViewController I have a UIView. I have that UIView linked up to a custom UIView class. Nested inside the UIView is a UITextField. I am trying to drag connect the UITextField to the UIViews.h file. Xcode won't let this happen, so I am trying to figure out if this is possible.
I am able to call a method inside my UIView from my UIViewController, so I think it's all wired up correctly.
Thanks

Did you add class by clicking file-add file?Try to relaunch xcoode.

Related

Cannot control-drag in xcode between cocoa touch uiview class and subview in storyboard

I'm new to xcode and iOS.
I'm following apple tutorial, but I can't figure out a thing.
In the tutorial, when there is the need of a connection between the storyboard and the ViewController.swift, it's done a connection using the control-drag from the storyboard to the viewController.swift, and it works like a charm.
If I add a subview to storyboard, apple does the connection and the declaration by code in a custom cocoa touch class that implements UiView Protocol, not using the control-drag.
Now, given the fact that is clear to me the code writted by apple, I'm just wondering why the control-drag doesn't work.
I've tried to do the same thing, adding a button via ui and then tried to control-drag to cocoa touch class, and I cannot do this.
But if I do the same thing, but trying to connect it to the ViewController.swift it works perfectly.
Now, I'm just wondering why this happens.
Can't I use control-drag with a custom UiView?
Thanks for answering.
You can only control-drag from outlet to view on xib, after creating outlet in code you will see a dot at the left side, you can drag from there to your view and outlet will work
In the storyboard, you have to set the class name to the view controller.
If you want to create a custom view that will have subview of it's own, you can do so using a Xib file (pretty much like a storyboard, but for only one view instead of for a whole app workflow) and then you'll be able to make all the connection you wish. Storyboard is not meant to design your customView. Connection are mainly used to provide a easy/cost-effective reach from the control grasp to it's main view's subviews (IBOutlets) or to '0 line' a target action pattern. One exception is with the custom tableView / collectionView cell though..
For connectioning between storyboard & class
you must in the
storyboard -> customClass -> chose your class

How to draw using Quartz 2D to my ViewController

This is sort of a beginner-level question. I have inherited an iOS project and it is implemented with a few ViewControllers with associated XIB files. The XIB files contain various widgets that are controlled by code in the ViewControllers (which I think is the standard way of constructing an app).
However, I need to do some custom drawing (rectangles, lines, circles, text) in between the widgets, and I'd like to use the Quartz 2D library to do this. I've never used Quartz2D, and most of the sample code I find is centered around the View, not the ViewController.
Most of it seems to do with implementing the "drawRect" method of your View. However, my ViewController does not have a "drawRect" function, as far as I can tell. Is there a way I can implement a "drawRect" function on my ViewController or whatever View it is controlling?
*** addendum:
I have researched and reminded myself that the operational UIView is a property of the UIViewController, and it seems like UIView is created automatically by the application and bundled together with my XIB and ViewController (I think we selected "also create XIB" when we were creating a ViewController, so the UIView is implied?). I don't see where this default UIView instantiation occurs. But I assume the way to draw to it is to subclass it?
If so, what is the cleanest way to subclass this UIView and get access to drawRect while maintaining the connection to the existing ViewController and XIB (or storyboard)? I inherited the project and this change needs to be low-impact.
Thanks for any help/thoughts.
Make a subclass of UIView and override -drawRect: to do your custom drawing. In the xib, select the view of your view controller, go to the Identity Inspector (third tab in the right sidebar in Xcode), and replace UIView with your custom subclass.

iOS UITextView delegate

I'm going to try to explain my problem as best I can.
I have a UIViewController, and inside that view I used the storyboard to drag an UITextView. My goal here is reading the touch points the user clicks on the UITextView, through the touchesBegin and touchesEnded methods. To do this I created a custom class called TextView, and on the storyboard I told that the class that is handling the UITextView is the new one. Doing that I can read the touch points when I click on the UITextView, but now I want to send that touch point data, back to the UIViewController, I'm trying to do this for 2 days now and nothing works!! I tried to create a delegate but without successs.
Make an instance of your custom class in your ViewController.m and use your methods to get the touch data inside your viewcontroller.

Multiple outlets with Multi-Scenes and ViewControllers for iOS

So I have have three scenes with three individual textFields. I set up three ViewControllers for each of the scenes to handle dismissing the keyboard on each respective textField in it's own scene. But I can't get the textField object to create a IBAction outlet using the control drag method. Even created a custom UITextField class to try and resolve the solution but that didn't seem to help. Any ideas why I can't get this to work?
Here is my Storyboard set up:
This is what it looks like when I try an control drag
So I finally found the solution. Even though the UITextField had it's own class the scene it's self I had was under the wrong UIViewController class. I selected the UIViewController by selecting the black bar underneath it (this can also be done using Document Outline or Shft+Cntrl+Click and selecting the proper UIViewController) and changing the Custom Class setting under the Identity Inspector to that of the UIViewController that I intend to interact with it.

Modify and redraw another UIView from the UIViewController

I have a flow issue in my iOS app from my subclassed UIView to its parent UIViewController.
Basically, I have a nib called preferences. It contains two sliders, two labels, and another UIView that will display a shape dictated by the two scroll bars (Stroke and opacity). I successfully painted the subclassed ui to the screen by setting the custom class of the UIView to a separate UIView we'll call subView. I have setters/getters for the scroll bars and they print out their values. How do i let the uiview class (pointed at the ui nib object) to update and redraw since it isn't referenced in the parent preferences class? I tried syntax like this:
[code]
IBOutlet SubClassUIView *subclassUI
[/code]
to no effect. It seems best to point a custom class at the UIView.
Any suggestions and advice would be much appreciated.
TL;DR can't modify subclassed uiview from "parent" uiviewcontroller
Sorry folks, i figured it out.
In addition to passing in a custom class that shares the same type as the IBOutlet (such as a UIView),
there MUST be a link referencing every object in in the .xib to its parent. In this case, the parent UIViewController needed a reference from the custom class ui to a IBOutlet UI. From there, some simple casting from generic and boring UIView to the custom class's unique methods makes for a complete flow.

Resources