initWithNibName method in storyboard

后端 未结 1 1171
抹茶落季
抹茶落季 2020-12-24 03:58

I am following Facebook\'s tutorial to post to a user\'s wall: http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/ and although it is made with a .xib projec

相关标签:
1条回答
  • 2020-12-24 04:11

    I just ran into this problem myself. Storyboards appear to not use initWithNibName:bundle:, but either initWithCoder:(NSCoder *)aDecoder or initWithStyle:(UITableViewStyle)style.

    The default implementations of the two methods look like:

    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:style];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    

    I've yet to use the initWithStyle version myself, but I'd imagine it's called for a UITableViewController. If in doubt, you could simply add both methods to the file, along with an NSLog() call that prints the method's name (or any other unique string). You can then run it in the simulator to see which is called, and delete the other.

    I'd strongly recommend against calling initWithNibName:bundle: yourself from any of the other init methods. Better to just move the code to the correct method.

    0 讨论(0)
提交回复
热议问题