我有兩個通用的應用程序...一個是給我一個EXC_BAD_ACCESS錯誤我做到這一點的應用程序委託時:EXC_BAD_ACCESS在[窗口addSubview:viewcontroller.view]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ScrollViewController *vc = [[ScrollViewController alloc] init];
[window addSubview:vc.view]; // EXC_BAD_ACCESS here
[window makeKeyAndVisible];
return YES;
}
我做的完全一樣的(相同的代碼,相同的滾動視圖控制器類)在我的其他應用程序,並得到沒有錯誤...我的滾動視圖加載正常。
這個問題讓我瘋狂。這裏是ScrollViewController實現:
@implementation ScrollViewController
- (void)loadView {
[super loadView];
UIScrollView *s = [[UIScrollView alloc] initWithFrame:[[self view] bounds]];
NSArray *a = [[NSBundle mainBundle] loadNibNamed:@"JCEKKeyboard" owner:self options:nil];
UIView *v = [a objectAtIndex:0];
[s setContentSize:CGSizeMake(400, 500)];
[s addSubview:v];
[[self view] addSubview:s];
}
向我們展示創建視圖的代碼,如果您說,它是在-init中完成的。 – jer 2010-07-16 11:59:49