在storyboard中的initWithNibName方法 [英] initWithNibName method in storyboard

查看:116
本文介绍了在storyboard中的initWithNibName方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注Facebook的教程,发布到用户的墙上: http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/
虽然它是用.xib项目考虑的,我已经能够到目前为止,我的故事板项目做的一切都很好。但是,我已经到了我需要把一些代码放入initWithNibName:bundle:方法,但我不能这样做,因为我使用的是storyboard。而且,由于很难判断何时调用该方法,所以我不能只写一个名为initWithNibName:bundle的方法,并从其他方法中调用它。如果任何人有任何想法如何解决我的问题,请说这样。谢谢。

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 project in mind, I have been able to do everything just fine with my storyboard project so far. However, I have come to the point where I need to put some code into the initWithNibName:bundle: method, but I cannot do this because I am using storyboard. And, since it's hard to tell when exactly the method would be called, I can't just write a method named initWithNibName:bundle: and call it from some other method. If anyone has any idea of how to solve my issue, please say so. Thanks.

推荐答案

我刚刚遇到这个问题。故事板似乎不使用 initWithNibName:bundle:,但是 initWithCoder:(NSCoder *)aDecoder initWithStyle:(UITableViewStyle)style

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;
}

我还没有使用initWithStyle版本,但我想象它被称为一个UITableViewController。如果有疑问,您可以简单地将两种方法添加到文件中,以及打印方法名称(或任何其他唯一字符串)的NSLog()调用。然后,您可以在模拟器中运行它来查看哪个被调用,然后删除另一个。

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.

我强烈建议不要调用 initWithNibName:bundle :自己从任何其他 init 方法。更好地将代码移动到正确的方法。

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.

这篇关于在storyboard中的initWithNibName方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆