我正在使用适用于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];
}
此外UIButton
和openTwitterSignInViewController
通过IB连接。
没有控制台输出,我不知道为什么。所以我正在添加截图。
LoginViewController.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
答案 0 :(得分:0)
也在.m文件中声明IBAction。方法名称在任何地方都应该相同:
-(IBAction)openTwitterSignInViewController:(id)sender;
答案 1 :(得分:0)
我解决了this answer之类的问题。我已将属性添加到主视图控制器并分配然后调用pushViewController
答案 2 :(得分:0)
您可以在显示此LoginViewController的viewcontroller中发布代码吗?这个问题是因为,从某个地方你的对象被过度释放。