私のiPhoneアプリはかなりシンプルですが、エラーになります。私のアプリケーションデリゲートは、このビューコントローラを開きます。UIButtonのシンプルなアプリ - iPhoneアプリケーションのエラー
#import "Launch.h"
@implementation Launch
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 100, 100, 100);
[button setTitle:@"Hello" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)buttonPressed {
NSLog(@"Button Pressed!");
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
//image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
ボタン付きの赤い画面です。ボタンをクリックすると、エラーメッセージなしでアプリがエラーになります。どうして?
ここは私のmain.mメソッドです。プログラムのエラーが出ると、 "return"行を指し、EXEC_BAD_ACCESSをスレッドに示します。
@selector(buttonPressed:) //add the :
、これを使用します:へ
#import <UIKit/UIKit.h>
#import "testAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([testAppDelegate class]));
}
}
バックトレースには有用な情報がありません。 main.mクラスを指すだけであり、有用なエラーメッセージはありません。 – CodeGuy
'buttonPressed'の' NSLog() 'にブレークポイントを設定します。 – zaph
私が言ったように、エラーメッセージはありません。私のコンソールに表示される最後のことは:現在の言語:auto;現在はobjective-c (gdb) – CodeGuy