2012-03-01 37 views
3

私は自分のプロジェクトにUIViewControllerのサブクラスを作成し、それを "RootViewController"によってモーダルプッシュされたビューにリンクしました。私は派生したクラスに全く変更を加えませんでしたが、 "SecondView"を押すと毎回黒に変わります。私は標準のUIViewControllerクラスにそのビューをリンクする場合、すべて正常に動作しますか?UIViewControllerのサブクラスで黒い画面が表示される

"SecondViewController"はUIViewControllerから派生しているので、問題はalloc/init関数と関係がありますが、どこから起動するのかはわかりません。

必要に応じて私の前にあるサンプルコードを提供できます。

これは派生サブクラスです:

#import "SecondViewController.h" 

@interface SecondViewController() 

@end 

@implementation SecondViewController 

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

- (void)loadView {} 

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

- (void)viewDidUnload { 
    [super viewDidUnload];} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); } 

@end 

ヘッダー:FYI、コメントは自動的にあまりにも生成され

#import <UIKit/UIKit.h> 

@interface SecondViewController : UIViewController 

@end 
+0

コードを入れてください、それは多くの助けになります –

+0

完了。希望が役立ちます。 – user1242094

+0

解決しました。 偶然、「関​​連」のトピックのトピックを見つけました。 理由を知りませんが、削除した後に - (void)loadView 機能がすべて正常に機能します。 サブクラスがXcodeによって自動的に生成されたので、まだ変わっています。 – user1242094

答えて

2
- (void)loadView 
{ 
    // 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, then you must NOT override this method. 
} 

2

変更この:これに

- (void)loadView 
{ 
    // 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, then you must NOT override this method. 
} 

- (void)loadView 
{ 
    [super loadView]; 
    // 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, then you must NOT override this method. 
} 

そして、それは動作します。

1

あなたは先のビューコントローラでこのような何かをしようとする場合がありますIBからセグエ中までそれを「ショー」の前にロードするビューを取得しようとしている場合は、この

-(void)loadView 
{ 
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 

    [view setBackgroundColor:[UIColor whiteColor]]; 

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 100, 100)]; 

    [label setText:@"HAI"]; 

    [view addSubview:label]; 

    self.view = view; 
} 
0

を試してみてください。

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 
[self.view layoutIfNeeded]; 
} 
関連する問題