Veita
Veita

Reputation: 519

How can I make IB create an action connection?

I'm stuck on a very frustrating problem with Xcode5's Interface Builder. Here's the issue:

I have a .xib file which contains a number of controls:

enter image description here

When I control drag from any of these controls into the .h or .m files corresponding to this .xib file, I am not given the option of creating an action:

enter image description here

The "FilesOwner" of the .xib file is set correctly to "MessageController" which is the ViewController for the .xib file.

This is frustrating because this issue is happening not just with this specific .xib / VC pair, but with all of the files in my project. I have already cleaned and rebuilt the project and closed and reopened XCode, but nothing seems to be working..

EDIT:

After reading your comments, I realize I should have been more specific in what I'm trying to do. In the screenshot above I chose the UIScrollView because I was under the impression that all controls were capable of generating some actions. So, here is a screen shot of what I am actually trying to do:

enter image description here

Am I making the same beginner mistake here? Should I be assigning this action in code with something like this instead of using IB:

[textView addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

Any More Advice?

Thank You!

Upvotes: 1

Views: 85

Answers (2)

staticVoidMan
staticVoidMan

Reputation: 20234

-addTarget:action:forControlEvents: is possible on UITextField because it inherits from UIControl but not UITextView because a UITextView does not inherit from UIControl and hence lacks this target-action ability.

You'd have to use the UITextViewDelegate and implement -textViewDidChange: method to do the same thing.

//1
//set delegate programmatically
[textView setDelegate:self];
//or via the IB: right-click drag UITextView to `File's owner`

//2
-(void)textViewDidChange:(UITextView *)textView
{
    //something happened with the textView!!
}

PS: You might want to rename your UITextView object to something other than simply textView.

Upvotes: 1

LJ Wilson
LJ Wilson

Reputation: 14427

Like the comments indicate, there are no actions you can make for a UIScrollView. If you are also having issues with actionable UI objects like UIButtons, UITextFields, etc:

Check to Make sure you have the right custom class defined for that xib file (files owner).

Image1

Also make sure that the selection for the assistant editor is set to Automatic.

Image2

Upvotes: 1

Related Questions