0

Is there any way to know when a custom object is finished with being initialized from inside the object's file? Or let me rephrase the question, why can't I call any method inside this method?

- (id)initWithCoder:(NSCoder *)coder {
    //NSLog(@"initWithCoder inside CustomObject (subclass of UIView)");
    self = [super initWithCoder:coder];
    if (self) {
        //... initialization here


        [self visibleEmptyButton]; //why does this method never get called?


    }
    return self;
}

EDIT:

-(void)viewDidLoad{



    NSLog(@"viewDidLoad inside CustomObject(subclass of UIView) is called"); //It never gets called
    [self viewDidLoad];
    //initialization here...


}
GourmetFan
  • 45
  • 1
  • 6

2 Answers2

1

(If the class you are init-ing is a subclass of UIViewController) Changing and setting things in the screen should be done after the view is loaded. Try doing it in this method:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self visibleEmptyButton];
    //Do the additional view altering here
}

If this method doesn't exist yet you can just add it to the .m file (no need to add it to the .h file).

Manuel
  • 10,153
  • 5
  • 41
  • 60
  • In that case you could create a UIViewController instance and make that the owner of you UIView. That Controller will then get the above mentioned call. – Manuel Jan 14 '13 at 14:15
0

In lieu of you're edit you could simply move the call to the UIViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    [TheInstanceOfYourViewClass visibleEmptyButton];
}

Also, to avoid making a whole bunch of small subview related methods public it often makes sense to create one method to handle the initial visual states.

T. Benjamin Larsen
  • 6,373
  • 4
  • 22
  • 32