Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GregD

macrumors member
Original poster
Aug 7, 2007
56
2
Im trying to insert the current date/time in a UITextView once the user hits the return key but without success.

Can anyone help point me in the right direction ? :)
 
With which part?

How do you mean?

I have a textview on interface builder hooked up to an IBOutlet and a property synthesized in DetailViewController.m (txtDetail)...

I was trying to see to start off with (before even thinking about adding a date) I could just add some text in when the user clicks onto UITextView however that doesn't work either:

PHP:
- (void)textViewDidBeginEditing:(UITextView *)textView { 
self.txtDetail.text = [self.txtDetail.text stringByAppendingString:@"Hello!"];
}

Unless i've got the wrong end of the stick completely on how to run the method?
 
How do you mean?

I have a textview on interface builder hooked up to an IBOutlet and a property synthesized in DetailViewController.m (txtDetail)...

I was trying to see to start off with (before even thinking about adding a date) I could just add some text in when the user clicks onto UITextView however that doesn't work either:

PHP:
- (void)textViewDidBeginEditing:(UITextView *)textView { 
self.txtDetail.text = [self.txtDetail.text stringByAppendingString:@"Hello!"];
}

Unless i've got the wrong end of the stick completely on how to run the method?

OK, so that's a sensible start. What have you done to debug it "not working"? Have you checked that the method is being called with an NSLog statement? Have you even set the instance that contains that method as the text view delegate?
 
OK, so that's a sensible start. What have you done to debug it "not working"? Have you checked that the method is being called with an NSLog statement? Have you even set the instance that contains that method as the text view delegate?

Well tried an NSLog(@"Hello"); within the method but nothing... Here's the code in case ive overlooked something obvious:

PHP:
DetailViewController.h

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {

	UITextView *txtDetail;
}


@property (nonatomic, retain) IBOutlet UITextView *txtDetail;
- (void)textViewDidBeginEditing:(UITextView *)textView;

PHP:
DetailViewController.m

@synthesize txtDetail;

- (void)textViewDidBeginEditing:(UITextView *)textView {
	NSLog(@"Hello");
	self.txtDetail.text = [self.txtDetail.text stringByAppendingString:@"Hello!"];
}

On interface builder ive connected the textview to to file owner txtDetail. Have I missed anything?

Appreciate the help :)
 
On interface builder ive connected the textview to to file owner txtDetail. Have I missed anything?

Appreciate the help :)

You need to give as much detail as possible: what connection. Have you connected the delegate property of the text view? If not then you cannot expect to receive delegate messages.
 
You need to give as much detail as possible: what connection. Have you connected the delegate property of the text view? If not then you cannot expect to receive delegate messages.

Yes I seem to be missing that. So i've added this to the .h:

PHP:
@interface DetailViewController : UIViewController <UITextViewDelegate, UIPopoverControllerDelegate, UISplitViewControllerDelegate> {

Connected textview so it now says "Referencing outlets: delegate textview" in interface builder.

However not too sure how to integrate this with the method...

I found this example but not sure how to implement:

PHP:
myAppDelegate *appDelegate 
	= (myAppDelegate *)[[UIApplication sharedApplication] delegate];
[[[appDelegate rootViewController] flipsideViewController] myMethod];
 
I don't see what the code you posted has to do with this at all. That is dealing the an application delegate, not a text view delegate.
 
I don't see what the code you posted has to do with this at all. That is dealing the an application delegate, not a text view delegate.

Got it working... as it's a splitviewui template I had to put it in DetailViewController.m and RootViewController.m

Now just wondering how I insert the date once the user presses return? :)
 
Usually the way to insert some content into an edit box when the user move the cursor into that box is not through the begin edit event, but through some type of focus event.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.