English 中文(简体)
适当使用装载 观点和观点
原标题:Proper use of loadView and viewDidLoad with UIViewController without nibs/xibs

当我没有刀刺的节目时,我的印象是,我需要打电话,以提出我的看法。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        // Custom initialization
        [self loadView];
    }
    return self;
}

(我已经确定尼比奥尼拉 = 无,因为没有尼伯。)

然后,我提出以下看法:

- (void) loadView {
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 367)];
    [self viewDidLoad];
}

这是从德洛德的角度考虑的。

如果我以这种方式要求收音和观看德洛德的话,我仍然不相信。 他们不会自动被叫。

问题在于:

装载 观点讨论

You should never call this method directly. The view controller calls this method when the view property is requested but is currently nil. If you create your views manually, you must override this method and use it to create your views. If you use Interface Builder to create your views and initialize the view controller—that is, you initialize the view using the initWithNibName:bundle: method, set the nibName and nibBundle properties directly, or create both your views and view controller in Interface Builder—then you must not override this method.

So, I don t understand how loadView gets called if I should never call it directly.

The default implementation of this method looks for valid nib information and uses that information to load the associated nib file. If no nib information is specified, the default implementation creates a plain UIView object and makes it the main view.

我不理解这如何奏效——制造痛苦的问讯。

If you override this method in order to create your views manually, you should do so and assign the root view of your hierarchy to the view property. (The views you create should be unique instances and should not be shared with any other view controller object.) Your custom implementation of this method should not call super.

If you want to perform any additional initialization of your views, do so in the viewDidLoad method. In iOS 3.0 and later, you should also override the viewDidUnload method to release any references to the view or its contents.

Okay, 到目前为止,它并没有说观点如何。 DidLoad被传唤。 因此,DidLoad:

意见 DidLoad Discussion

This method is called after the view controller has loaded its associated views into memory. This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method. This method is most commonly used to perform additional initialization steps on views that are loaded from nib files.

如何?

自2006年以来 我的法典没有自动提及这些方法,我不得不认为,我必须自称。 但我仍未得到明确的理解,即文件表明这是正确的。

最佳回答

As the documentation says, you should not call these methods yourself.

打算如何工作,这就是说,国际不动产业联合会的法典将把你的载荷称作你。 观察方法如果和何时实际上需要将控制者的观点等级放在筛选上。

具体来说,如果任何密码试图读到你的视力控制器上的view 财产,而且该财产为零,则《国际不动产合同》的《编码将称为<代码>。 观点方法。 页: 1 观点 yourself,因此,违约执行将回头来试图将观点等级从氮中排出。

当你试图提出你的观点控制者时,情况就自动发生。 (如果你的视力控制者必须响应记忆压力而放弃其观点,那么你可以自由采取的另一个行为,而且你不想叫 yourself)

如果你们不认为这些方法是控制员,那么你如何提出这种看法的控制者就必然会错了,这妨碍国际会计师联合会的《框架守则》要求采用这些方法。 该守则和他人可以帮助你发现这种错误。

在你试图确定<><> bug之前,你应从你的法典中删除:

[self loadView]
[self viewDidLoad]

然后,在你自己执行<代码>viewDidLoad时,你将要求将超级执行称为[super viewDid Load]

www.un.org/Depts/DGACM/index_spanish.htm 重载 观点 你们唯一的自我责任。 某些有效观点。 这就是说。 IDKit代码然后看见,并打电话viewDidLoad

希望会有所帮助。

问题回答

<>Firoze Lafeer的回答是正确的,我只想表明如何forceload。 The view property the correct way:

(void)self.view;

You should not do this! If you must, you are doing something wrong, but do not call -loadView and -viewDidLoad yourself at any circumstances.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签