English 中文(简体)
IDViewController采用的观点-何时使用?
原标题:ViewDidLoad method in UIViewController - when does it get called?

页: 1 发射 主计长,在座标首当其冲时用我的手提启动:

@interface LaunchController : UIViewController<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

Then, when a button is clicked, I push another view controller:

 MainController *c = [[MainController alloc] initWithImage:image];
 [self presentModalViewController:c animated:NO];

主要主计长有以下施工人员,我使用:

- (id)initWithImage:(UIImage *)img
{
    self = [super init];
    if (self) {
        image = img;
        NSLog(@"inited the image");
    }

    return self;
}

之后,委员会有意见 两种方法如下:

- (void)viewDidLoad
{
    NSLog(@"calling view did load");
    [super viewDidLoad];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [self.view addSubview:imageView];
    NSLog(@"displaying main controller");
}

在方案实施时,我看到<代码>MainController的构造者(由于NS Carlo的输出),但viewDid Load。 尽管我打电话<>,但从来没有听说过。 为什么如此? 为什么要打上<代码>viewDidLoad?

最佳回答

我认为,这是以下一点。 如您需要IDViewController内view的财产,将以 la方式装载。

- (UIView *)view 
{
   if (_view == nil) {
      [self loadView]; //< or, the view is loaded from xib, or something else.
      [self viewDidLoad];
   }

   return _view;
} 

在<代码>view 初始化后,将打电话viewDid Load,以通知.

问题回答

You view view view view view view view 观点(如果你不使用轴心文件,那将形成你的观点控制者的看法)。

因此,你的看法没有装满。 迪德·洛德从未被传唤。

通常,你将使用<条码>initWith NibName:,以启动新的观点控制器,然后树立形象(从而暴露出作为财产的形象)。

意见 各位控制人员一旦发现财产,即第一次显示或要求归还财产时,将立即叫DidLoad(例如,有一些代码,电话c.view

理由不叫DidLoad是因为你装着一种观点。

3. 在您的惯用方法中:

 self = [super init];

也就是说,你只是从头开始便 naked。 不从刀子中装载一只。

而是试图:

self = [super initWithNibName:nil bundle:nil];

如果有轴心或刀子,其名称与观点控制者类别相同,就应当找到。 否则,你就只能给一刀切。

UPDATE:

如果你不使用刀具,那么适当的方法是NOT viewDidLoad。 页: 1

在你的具体案例中,只是把目前认为是德洛德的话装进了意见。





相关问题
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, ...

热门标签