2012-02-19 56 views
0

我找不出爲什麼該代碼導致應用程序崩潰。應用程序崩潰與「無法恢復先前選定的幀」消息

AppDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    self.rootViewController = [[[RootViewController alloc]init]autorelease]; 

    [self.window setRootViewController:self.rootViewController]; 


    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

這裏是RootViewController.m代碼

-(void)loadView 
{ 
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 10, 10)]; 
    [view setBackgroundColor:[UIColor lightGrayColor]]; 
    [self.view addSubview:view]; 
    [view release]; 
} 

我得到的消息在調試器

Unable to restore previously selected frame. 

Here is screenshot

回答

3

loadView應該是設置的說法。它在self.view爲零時被調用。現在您打電話給[self.view addSubview:view];UIKit調用loadView,並創建一個無限遞歸。你應該在這裏做self.view = view;

+0

Get it!謝謝 ! – OhDoh 2012-02-19 12:42:56

1

loadView負責首先設置視圖。你錯過了這樣做。相反,您添加了一個視圖self.view。

通過更改下面一行代碼:

self.view = view; 

,而不是[self.view addSubview:view];

而且最好是從函數返回之前調用[super loadView]

相關問題