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.
Related
I have a class I call InputView that is a subclass of UIView that contains a UITextField and a UILabel. Due to how my InputView is designed, I have it implement the UITextFieldDelegate protocol so I can do a bunch of things when its UITextField is edited.
I then have a View Controller that has multiple InputView's in it. I want to create a new InputView whenever the first InputView in the VC is filled up. Now I could do this using a simple check in the function that is called when a UITextField ends editing, and just check if the InputView is filled up or not, but as I said, InputView already implements the UITextFieldDelegate protocol.
I want to "send" a signal from an InputView, that I can catch in my VC and then run a function that creates a new InputView. If you're confused, see the following image:
You can use notification to trigger an action in you View Controller.
Use this answer
How to post and receive an notification?
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.
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.
I followed this discussion: UITableView issue when using separate delegate/dataSource, and even though I found it super informative and useful, I have a follow up question:
So I've got a similar setup where I have a UITableView within the UIView. The UIView is controlled by it's own UIViewController (let's call it MyUIViewController) and also I moved the delegate and datasource for the UITableView into a separate subclass of UITableViewController (say, MyUITableViewController).
Everything works fine with the tableView.
The question is, how do I make a callback from MyUITableViewController to the MyUIViewController? For example, if the user selects a cell under the tableView which triggers didSelectRowAtIndexPath, I need to update something on the UIView which is actually a parent of this UITableView. So I basically need to send a message to MyUITableViewController. How would I do that?
You can use a delegate pattern in this case. I have a similar answer with sample code in this SO . In your case, the parent view controller is MyUIViewController. And the child view controller is MyUITableViewController.
I have seen Code snippets where people have written touchesBegan and touchesEnded in the View Controller of a view.
I am relatively new to iOS development and am unable to understand how is that possible.
Aren't these methods of UIView class that we override in our custom views.
and If its possible then If I call view's touches Event which version gets the priority ?
The one in the View controller or one in the View itself.
As you can easily look up in the documentation, the touches...:withEvent: family of methods is declared in the UIResponder class. Since both UIView and UIViewController inherit from UIResponder, both classes have access to the methods and can override them.
As to the question which implementation gets priority if both are implemented, that is defined by the responder chain. Touch events travel up the responder chain until they find an object that wants to handle the event. Since a view is placed before its view controller in the responder chain, the implementation in the view class would be executed.
The view controller has copies of these methods as well. It's for convenience so you don't have to create a custom UIView subclass just to handle touch interaction.
If both the view and the view controller implement these methods then they both get called when the user touches the screen, however I believe that the ones on the view get called first.
Note that as of iOS 3.2/4.0, UIGestureRecognizers are generally a much easier way to do most types of touch interaction. There's rarely any need to use touchesBegan and touchesEnded any more.