0
我正在使用多個視圖控制器和導航控制器的應用程序。當應用程序運行並執行以下代碼時,它會在嘗試添加子視圖時引發異常。將UINavigationController添加到窗口時EXC_BAD_ACCESS
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
}
我聲明導航控制器像這樣:
@interface SimpleContactsAppDelegate : NSObject <UIApplicationDelegate> {
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
UIWindow *window;
UINavigationController *navigationController;
// view for adding new contacts
UIViewController *newContactView;
UIButton *addButton;
// controls for the addContactView
UIButton *saveContactButton;
UITextField *nameField;
UITextField *emailField;
UITextField *phoneField;
UITableView *contactsTable;
}
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIButton *addButton;
@property (nonatomic, retain) IBOutlet UITableView *contactsTable;
// controller and fields for the form
@property (nonatomic, retain) IBOutlet UIViewController *newContactView;
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *emailField;
@property (nonatomic, retain) IBOutlet UITextField *phoneField;
@property (nonatomic, retain) IBOutlet UIButton *saveContactButton;
我已經連接在導航控制器在XIB的委託對象。隨時看看我的全部源:https://github.com/agmcleod/SimpleContacts/tree/parttwo
我試過用NSZombie儀器,但它似乎並沒有停下來,讓我檢查什麼特別出錯。它也有時會繼續運行,並且不會終止。我最終不得不使用活動終端強制退出它。
非常感謝! :d。這固定了它。重命名文件,並將自我添加到navigationController。 – agmcleod 2011-05-29 23:01:07