Very basic Objective-C Question

Discussion in 'iOS Programming' started by jskidmore, Aug 24, 2008.

  1. macrumors newbie

    Joined:
    Jul 13, 2008
    #1
    Okay, I am completely new to Objective-C so forgive me.

    I am trying to run a command when the MainView is initially loaded, so I figured I would need to override the constructor. I tried overriding init and initWithFrame, but it didn't work.

    How can I get a command to run (sendDate = NSDate date;) when the UIView is initially loaded?

    Thanks a bunch.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If your view is inside a NIB you will need to override initWithCoder, if not just use initWithFrame.

    Code:
    - (id)initWithFrame:(CGRect)frame {
        if ([super initWithFrame:frame]) {
            // put your initialization stuff here
        }
        return self;
    }
    
    - (id)initWithCoder:(NSCoder *)coder {
        if ([super initWithCoder:coder]) {
            // put your initialization stuff here
        }
        return self;
    }
     

Share This Page