我已經寫了iOS5的xcode 4.2中按鈕點擊操作的示例代碼。EXEC_BAD_ACCESS在IBAction的iOS5中
下面是代碼
.H
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
@property(strong,nonatomic) IBOutlet UIButton *button;
-(IBAction)changed;
@end
.M
#import "FirstViewController.h"
@implementation FirstViewController
@synthesize button=_button;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
- (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
{
[_button addTarget:self action:@selector(changed) forControlEvents:UIControlEventTouchUpInside];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(IBAction)changed
{
NSLog(@"clicked");
}
- (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 YES;
}
@end
但是,當我按一下按鈕。我得到例外。如何解決這個問題?同樣是在的iOS 4.3
顯示崩潰日誌並在應用程序崩潰.. – Sarah 2012-02-02 06:07:29
將您的來電超到你的'viewDidLoad'方法 – Rog 2012-02-02 06:09:30
頂部如果我點擊按鈕的聲明,在main.m文件 – Bharath 2012-02-02 06:22:28