我是Xcode和Objective-C的初學者,我想在沒有nib文件的代碼中創建一個視圖控制器,並且以我想要的形式來塑造它。目前有了這個非常簡單的代碼,我甚至無法改變背景顏色,因爲EXC_BAD_ACCESS。不良訪問 - iPhone Xcode 4
我在互聯網上看到這是內存管理的東西,但我似乎無法找到解決這個問題。我的代碼片段:
AppDelegate.h
#import <UIKit/UIKit.h>
#import "DefaultViewController.h"
@class DefaultViewController;
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UIViewController *rootViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIViewController *rootViewController;
@end
AppDelegate.m
@synthesize window = _window;
@synthesize rootViewController = _rootViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *rvc = [[DefaultViewController alloc] init];
self.rootViewController = rvc;
[rvc release];
[self.window addSubview:self.rootViewController.view];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[_window release];
[_rootViewController release];
[super dealloc];
}
我通過做視圖控制器,右鍵 - >新文件和UIViewController子類沒有XIB!在loadView我只試試這個:
self.view.backgroundColor = [UIColor redColor];
我認爲你需要向我們展示的代碼爲你DefaultViewController。 – Abizern
發佈跟蹤堆棧。 – WrightsCS