应用程序因 UITextViewDelegate 崩溃

发布于 2024-09-16 10:37:17 字数 1515 浏览 9 评论 0原文

我是 iPhone 编程和 Objective-C 新手,我的 UITextView 遇到了一些问题。我有一个以文本视图作为其子视图的视图。我创建了一个单独的类,我想将其作为文本视图的代理。在这个委托类的标头中,我有这样的语句:

@interface MessageTextViewDelegate : NSObject UITextViewDelegate

UITextViewDelegate 周围使用尖括号。我还将界面生成器中的文本视图连接到我的委托类,该类是我在界面生成器中创建为对象的。但是,当我运行应用程序并单击文本视图时,应用程序崩溃了。

当我尝试在代码中初始化文本视图委托的实例并将文本视图的委托设置为该实例时,也会发生同样的事情。当我的应用程序中没有委托时(即它未在界面生成器中连接或未在代码中键入),应用程序将运行。不过,我需要委托,以便当键盘出现时我可以在文本视图上执行动画调整大小。
您能否帮助我编写代码或我应该在 Interface Builder 中做什么以使应用程序通过委托运行?

@willcodejavaforfood

当我点击 textView 字段时收到以下错误消息:

[会议开始于2010-08-29 17:39:50 -0400。] 将程序加载到调试器中... GNU gdb 6.3.50-20050815(Apple 版本 gdb-962)(UTC 2008 年 7 月 26 日星期六 08:14:40) 版权所有 2004 自由软件基金会 GDB 是免费软件,受 GNU 通用公共许可证保护,您可以 欢迎在某些条件下对其进行更改和/或分发其副本。 输入“显示复制”以查看条件。 GDB 绝对没有任何保证。输入“显示保修”以了解详细信息。 此 GDB 配置为“i386-apple-darwin”。警告:无法读取“/System/Library/Frameworks/UIKit.framework/UIKit”的符号(未找到文件)。 警告:无法从“UIKit”读取符号(尚未映射到内存中)。 警告:无法读取“/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics”的符号(未找到文件)。 警告:无法从“CoreGraphics”读取符号(尚未映射到内存中)。 程序已加载。 共享库应用加载规则全部 附加到程序:`/Users/vivek/Library/Application Support/iPhone Simulator/User/Applications/86E8C2CB-3CB7-4615-BF2F-82F3B8982EB3/TestApp.app/TestApp',进程1493。 杀 杀死目标时出错(无论如何都要杀死):警告:函数“macosx_kill_inferior_safe”中“/SourceCache/gdb/gdb-962/src/gdb/macosx/macosx-nat-i​​nferior.c”第1987行出错:(os/kern )失败(0x5x) 退出

调试器已退出,状态为 0。

I'm new to iPhone programming and Objective-C and am having some trouble with my UITextView. I have a view with a text view as its subview. I created a separate class which I want to be the delgate of the text view. In my header for this delegate class, I have the statement:

@interface MessageTextViewDelegate : NSObject UITextViewDelegate

with angle brackets around UITextViewDelegate. I also connected the text view in interface builder to my delegate class, which I created as an object in interface builder. When I run my application, however, and click on the text view, the application crashes.

The same thing happens when I try to initialize an instance of the text view delegate in code and set my text view's delegate to be that instance. When I don't have the delegate in my application (i.e. it is not connected in interface builder or it is not typed out in code), the application runs. I need the delegate though so that I can perform an animated resize on the text view when the keyboard shows up.

Could you please help me either with the code or with what I should do in Interface Builder to make the application function with the delegate?

@willcodejavaforfood

I get the following error message when I tap the textView field:

[Session started at 2010-08-29 17:39:50 -0400.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/vivek/Library/Application Support/iPhone Simulator/User/Applications/86E8C2CB-3CB7-4615-BF2F-82F3B8982EB3/TestApp.app/TestApp', process 1493.
kill
error while killing target (killing anyway): warning: error on line 1987 of "/SourceCache/gdb/gdb-962/src/gdb/macosx/macosx-nat-inferior.c" in function "macosx_kill_inferior_safe": (os/kern) failure (0x5x)
quit

The Debugger has exited with status 0.

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

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

发布评论

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

评论(3

杀手六號 2024-09-23 10:37:17

通常,您会将 IB 中的 UITextView 与 UITextView 类型的 MessageTextViewDelegate 类中的属性连接起来。即在代码中创建以下内容:

@interface MessageTextViewDelegate

     UITextView *myTextView;

@property (nonatomic, retain) IBOutlet UITextView *myTextView;

@implementation MessageTextViewDelegate

@synthesize myTextView

然后将 IB 中的文本视图对象与 myTextView 属性连接起来。

You would normally connect the UITextView in IB with a property in your MessageTextViewDelegate class of type UITextView. That is create the following in your code:

@interface MessageTextViewDelegate

     UITextView *myTextView;

@property (nonatomic, retain) IBOutlet UITextView *myTextView;

@implementation MessageTextViewDelegate

@synthesize myTextView

You then connected your text view object in IB with the myTextView property.

内心荒芜 2024-09-23 10:37:17

根据生成的错误,您的项目似乎未正确编译应用程序。我将从“清理”所有目标开始并进行完整的重新编译。

based on the errors that are generated, it looks like your project is is not compiling the application correctly. I would start with "cleaning" all targets and do an complete recompile.

睡美人的小仙女 2024-09-23 10:37:17

如果我正确理解你的问题,那么它:

如果你有一个 ViewController“A”并且它有一个带有 textview“B”的子视图...

为了解决你的问题,
将 ViewController“A”设置为 TextViewDelegate。然后你就可以处理事情了。

干杯,

昆贾尔

If I am correctly understanding your problem then its:

If you have a ViewController "A" and it has a subview with textview "B"...

To solve your problem,
make ViewController "A" your TextViewDelegate. You can then handle things.

Cheers,

Kunjal

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