我正在为 iOS 4.1 开发一个带有 Xcode 4.3.2 的 Iphone 应用程序
我在 IB 的 UIView 中添加了一个 UIButton 并将其与 IBAction 连接。但是当我按下按钮时,我得到了 EXC_BAD_ACCESS 错误。
我在创建项目时启用了 ARC。
在这个错误和谷歌搜索之后,我了解到糟糕的内存管理会导致这个错误;但我无法确定是什么导致了这个问题。我怎样才能找到问题?
.h 文件包含
-(IBAction)openTwitterSignInViewController:(id)sender;
.m 文件包含
- (void)openTwitterSignInViewController:(id)sender{
UIViewController *secondViewController = [[TwitterSignInViewController alloc] initWithNibName:@"TwitterSignInViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
}
也通过 IB 连接UIButton
。openTwitterSignInViewController
没有控制台输出,我不知道为什么。所以我添加了一个截图。
登录视图控制器.m
#import "LoginViewController.h"
#import "Helper.h"
#import "TwitterSignInViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
@synthesize topBarText, userNameText, passwordText, passwordReminderButton, loginButton;
@synthesize signInTwitterButton, registerButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
userNameText.leftView = paddingView;
userNameText.leftViewMode = UITextFieldViewModeAlways;
passwordText.leftView = [NSKeyedUnarchiver unarchiveObjectWithData:
[NSKeyedArchiver archivedDataWithRootObject: paddingView]];
passwordText.leftViewMode = UITextFieldViewModeAlways;
topBarText.font = [UIFont fontWithName:@"Neo Sans Pro" size:14 ];
userNameText.font = [UIFont fontWithName:@"Neo Sans Pro" size:14];
passwordText.font = [UIFont fontWithName:@"Neo Sans Pro" size:14];
passwordReminderButton.titleLabel.font = [UIFont fontWithName:@"Neo Sans Pro" size:14];
loginButton.titleLabel.font = [UIFont fontWithName:@"Neo Sans Pro" size:14];
registerButton.titleLabel.font = [UIFont fontWithName:@"Neo Sans Pro" size:14];
}
- (IBAction)openTwitterSignInViewController:(id)sender{
TwitterSignInViewController *secondViewController = [[TwitterSignInViewController alloc] initWithNibName:@"TwitterSignInViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
至少我通过启用 Zombie Objects 获得了控制台输出。这是输出。但我还找不到错误
2012-08-01 21:11:30.569 adMingle[3156:f803] *** -[LoginViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x6857420