加载 inputAccessoryView 时出现问题

发布于 2024-10-21 16:51:53 字数 942 浏览 3 评论 0原文

我有一个仅由 UITextView 组成的应用程序。应用程序加载后,键盘就会出现,并且 AccessoryView 会加载到键盘顶部以便将其关闭。

这非常有效,直到我决定在应用程序加载时不想加载键盘。问题是,每当我尝试编辑文本时,应用程序就会崩溃(EXC_BAD_ACCESS)。我真的不明白为什么会这样。这是我的代码 - 标记了导致应用程序崩溃的段落:

- (void)viewWillAppear:(BOOL)animated {

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

然后:

- (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 语句,则应用程序可以工作......但我没有附件视图。有可能我在 InterfaceBuilder 中做错了什么吗? AttachmentView 是我的 ViewController 中的一个单独的视图。不过,它已正确连接(如果我在键盘打开的情况下启动应用程序,它确实可以完美工作)。

任何想法将不胜感激。抱歉,如果这是显而易见的,但我仍然是一个初学者,这些事情引起了巨大的头痛。

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 possible 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林很绿却致人迷途 2024-10-28 16:51:54

当您尝试向已释放的对象发送消息时,会发生 EXC_BAD_ACCESS 错误。如果您使用返回自动释放对象的便捷方法,请确保在设置 ivar 时调用保留。

如果这不起作用,您可以考虑使用 NSZombieEnabled 来跟踪向已释放对象发送消息的位置。

我找到了一些指南,您可以看一下:

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

http://collat​​eraldamag3.blogspot.com/2009/11/iphone-tutorial-nszombieenabled-and.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文