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