Xcode iPhone/iPad - Insert date/time on hitting return

Discussion in 'iOS Programming' started by GregD, Aug 15, 2010.

  1. macrumors member

    Joined:
    Aug 7, 2007
    #1
    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 ? :)
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. thread starter macrumors member

    Joined:
    Aug 7, 2007
    #3
    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?
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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?
     
  5. thread starter macrumors member

    Joined:
    Aug 7, 2007
    #5
    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 <UIPopoverControllerDelegateUISplitViewControllerDelegate> {

        
    UITextView *txtDetail;
    }


    @
    property (nonatomicretainIBOutlet 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 :)
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    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.
     
  7. thread starter macrumors member

    Joined:
    Aug 7, 2007
    #7
    Yes I seem to be missing that. So i've added this to the .h:

    PHP:
    @interface DetailViewController UIViewController <UITextViewDelegateUIPopoverControllerDelegateUISplitViewControllerDelegate> {
    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 sharedApplicationdelegate];
    [[[
    appDelegate rootViewControllerflipsideViewControllermyMethod];
     
  8. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    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.
     
  9. thread starter macrumors member

    Joined:
    Aug 7, 2007
    #9
    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? :)
     
  10. macrumors 6502

    Joined:
    Sep 17, 2007
    #10
    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.
     

Share This Page