• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problems with firstResponder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with firstResponder


  • Subject: Problems with firstResponder
  • From: Geert-Jan Korsbø Nilsen <email@hidden>
  • Date: Wed, 31 Aug 2011 23:05:03 +0200

Im working on a tiny app just to learn cocoa, and Im having a hard time with setting FirstResponder to some NSTextFields.

When the view opens, I want the first NSTextField, clientNumber, to be selected, so I trigger [clientNumber becomeFirstResponder] at the end of my loadView method, but it does not select the text field.
But when I click the button that fires the (IBAction)addToArray method, it selects the right text field. Further do I have another text field, it should contain integers only, so I have a crude verification for it. When the content is not a int, I get a beep, just like it should, but it does not select the text field.

Here is my code:


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
      NSLog(@"initWithNibName");
    }
    return self;
}

- (void)viewWillLoad {
    NSLog(@"viewWillLoad");
}

- (void)viewDidLoad {
    NSLog(@"viewDidLoad");
    [self initNewInvoice];
}

- (void)loadView {
    NSLog(@"loadView");
    [self viewWillLoad];
    [super loadView];
    [self viewDidLoad];
    [clientNumber becomeFirstResponder];
}

- (void)awakeFromNib
{
    NSLog(@"awakeFromNib");
}

- (IBAction)saveInvoice:(id)sender
{
    [invoiceCredit becomeFirstResponder];
}

- (IBAction)addToArray:(id)sender
{
    [clientNumber setStringValue: @"Toodeloo"];
    [clientNumber becomeFirstResponder];
}

- (IBAction)updateCreditDays:(id)sender
{
    if(invoiceCredit.intValue){
        [self updateCredit];
    }else{
        NSBeep();
        [invoiceCredit becomeFirstResponder];
    }
}


I really hope someone can help me out here.

Regards,


GJ Nilsen

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problems with firstResponder
      • From: Ron Fleckner <email@hidden>
  • Prev by Date: Re: ARC + CF types
  • Next by Date: Re: ARC + CF types
  • Previous by thread: Re: Size of a file on disk
  • Next by thread: Re: Problems with firstResponder
  • Index(es):
    • Date
    • Thread