我有一個導航控制器,其中包含一些按鈕的視圖,但是當我按下按鈕時,我得到一個EXC_BAD_ACCESS錯誤。因爲目標設置正確,我不能認爲我做錯了。它崩潰了按鈕是以編程方式添加還是通過IB添加。UIButton崩潰的應用程序觸摸
按鈕代碼:
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 incase,以任何方式幫助。
- (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;
}
嘗試放置斷點並讓我們知道它崩潰的位置 – 2012-04-11 15:33:04
我應該在哪裏放置它們?該應用程序崩潰時按下按鈕,其餘的代碼只是添加各種其他UI的東西子視圖。 – NinjaLikesCheez 2012-04-11 15:35:28