views:

34

answers:

2

Hi,

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 delgate?

Thank you!!

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

A: 

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.

ennuikiller
Hi ennuikiller, I tried doing this but my application still crashes. Do I need to initialize an instance of the delegate somewhere in my code also?
NoobjectiveC
A: 

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.

Aaron Saunders