开发者

Problems with loading inputAccessoryView

I have an app which simply consists of an UITextView. Once the app loads, the keyboard appears and an AccessoryView is loaded on top of the keyboard so as to dismiss it.

This worked splendid until I decided that I don't want to load the keyboard when the app loads. The problem is that whenever I try to edit the text, the app crashes (EXC_BAD_ACCESS). I don't really understand why this should be. Here is my code -- the passage is marked which crashes the app:

- (void)viewWillAppear:(BOOL)animated {

// Make the keyboard appear when the application launches.
[super viewWillAppear:animated];
// [textView becomeFirstResponder];} 

And then:

- (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView {


    // this crashes app if no keyboard is loaded in viewdidload:

        if (textView.inputAccessoryView == nil) {
        textView.inputAccessoryView = accessoryView;    
        self.accessoryView = nil;

}


    return YES;
}

If I comment out the last if statement, the app works ... but I don't have my accessoryView. May it be poss开发者_开发问答ible that I've done something wrong in InterfaceBuilder? accessoryView is a separate view in my ViewController. It's properly connected, though (and it does work perfectly if I start with the app with keyboard on).

Any ideas would be very much appreciated. Sorry if this is obvious, but I'm still a beginner and these things cause huge headaches.


EXC_BAD_ACCESS errors happen when you try to send a message to an object that has been deallocated. Make sure that when you set your ivars you are calling retain if you use a convenience method that returns an autoreleased object.

If this does not work, you can look into using NSZombieEnabled to track where you are sending a message to a deallocated object.

I found a couple guides you could take a look at:

http://www.fromconcentratesoftware.com/2007/08/09/nszombieenabled-for-the-debugger-adverse/

http://collateraldamag3.blogspot.com/2009/11/iphone-tutorial-nszombieenabled-and.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜