开发者

UITextView delegate class crashes on clicking the textview?! What's going on?

So I saw this question: How do you connect the "delegate" outlet of a UITextView to a class that implements UITextViewDelegate protocol?

My problem is similar to what booboo is describing in the second response (not the one marked as the answer.)

I have a MyViewController which implements UITextViewDelegate. In interface builder for the nib, inside the view I have selected the TextView and assigned it's delegate to the File Owner (which is MyViewController.)

MyViewController has implemented

- (void)textViewDidBeginEditing:(UITextView *)textView
{
NSLog(@"TextView EDIT %@",textView);
}

Every single time I test my app though, as soon as I click on the TextView I get an EXC_BAD_ACCESS crash. If I remove the delegate link in IB then the keyboard pops up fine.

I have also tried creating an IBOutlet UITextView to the textview inside MyViewController and linking the TextView to this IBOutlet in the File Owner. In the viewDidLoad then I assign:

myDescriptionTextField.delegate = self;

But this also results in the same issue of an EXC_BAD_ACCESS as soon as I click the TextView.

Inside XCODE at the top when it crashes the stac开发者_Go百科k trace(i think this is what it is ?) of where it crashes says:

objc_msgSend ??

-[UIResponder becomeFirstResponder]
-[UITextView becomeFirstResponder]
-[UITextInteractionAssistant setFirstResponderIfNecessary]

... etc?

Does this help? I'm so lost on what this issue is? Everything seems linked correctly.


I would check how the MyViewController object is created and managed (how you keep the object in your application). It is possible that while your UITextView exists as it becomes a subview of one of your UIView object (addSubview retains the subview), the MyViewController object itself is released from the memory after you build up your view hierarchy.

myDescriptionTextField.delegate = self;

does not retain self, as retaining a delegate may cause a problem of reference cycles.

Check this, and if it doesn't solve the problem try debugging with NSZombieEnabled because it will tell you where exactly you make a reference to an invalid object.


Also I got your problem!

I solve by passing weak delegate instead of self

__weak typeof(self) weakSelf = self;

than use weakSelf !!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜