いくつかのボタンを含むビューを保持するnavigationControllerがありますが、ボタンを押すとEXC_BAD_ACCESSエラーが発生します。目標が正しく設定されているので、自分が間違っていることは考えられません。ボタンがプログラムで追加されたか、IBを介して追加されたかに関係なく、クラッシュします。
ボタンコード:
UIButton *reportsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
reportsButton.frame = CGRectMake(20, 100, 100, 50);
[reportsButton setTitle:@"Reports" forState:UIControlStateNormal];
[reportsButton addTarget:self action:@selector(reportsButtonTouched:) forControlEvents:UIControlEventTouchUpInside];
機能ボタンがアクセスしようとしています:
- (void)reportsButtonTouched:(id)sender
{
NSLog(@"working");
}
エラー:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); //EXC_BAD_ACCESS code=1
}
ボタンがアクセスしようとしている機能が存在します。
たぶんそれは私が気付いていないNavigationControllerの機能についての何かですが、私は以前に問題なくこれを実行しました。
回答ありがとうございます。以前このサイトから得た助けに本当に感謝しています。
編集:これは私のAppDelegatesのdidFinishLaunchingであり、何らかの形で役立ちます。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *homevc = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homevc];
[self.window addSubview:nav.view];
[self.window makeKeyAndVisible];
return YES;
}