0

我正在为 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 连接UIButtonopenTwitterSignInViewController

没有控制台输出,我不知道为什么。所以我添加了一个截图。 在此处输入图像描述

登录视图控制器.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
4

3 回答 3

0

在 .m 文件中也声明一个 IBAction。方法名称应该在所有地方都相同:

-(IBAction)openTwitterSignInViewController:(id)sender;
于 2012-08-01T13:05:10.890 回答
0

我像这个答案一样解决了我的问题。我已经向主视图控制器添加了一个属性并分配然后调用pushViewController

于 2012-08-01T18:34:12.957 回答
0

您可以从显示此 LoginViewController 的视图控制器中发布代码吗?这个问题是因为,从某个地方你的对象被过度释放。

于 2012-08-01T18:34:21.917 回答