iPhone 上的 EXC_BAD_ACCESS

发布于 2024-12-08 23:49:31 字数 3013 浏览 3 评论 0原文

我有以下内容:

Class Number1

.h 文件:

myAudiCiviliteInputViewController *civiliteInputViewController;

.m 文件:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableViewEtape4 deselectRowAtIndexPath:indexPath animated:NO];

    civiliteInputViewController = [[myAudiCiviliteInputViewController alloc] init];
    [self.navigationController pushViewController:civiliteInputViewController animated:YES];
    [civiliteInputViewController release];

    UIButton* customView = [UIButton buttonWithType: UIButtonTypeInfoLight];
    [customView setFrame:CGRectMake(0, 0, 60, 31)];
    [customView setImage:[UIImage imageNamed:@"nc_btn_ok.png"] forState:UIControlStateNormal];
    [customView addTarget:self action:@selector(okPressed) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *envoyerButton = [[UIBarButtonItem alloc] initWithCustomView: customView];
    [self.navigationController.navigationBar.topItem setRightBarButtonItem:envoyerButton];
    [customView release];

}

-(void) okPressed{

        self.civiliteString= civiliteInputViewController.civiliteInputString;
        civiliteLabel.text = self.civiliteString;

        [self.navigationController popViewControllerAnimated:YES];
}

当我单击 tableView 时,我移动到 Number 2 类。

Class Number2 myAudiCiviliteInputViewController

@synthesize civiliteInputString;

- (void)dealloc
{
    [civiliteInputString release];
    [tabelViewCivilite release];
    [tableViewArray release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    tableViewArray = [[NSMutableArray alloc] initWithObjects:@"Madame", @"Mademoiselle", @"Monsieur", nil];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellRecherchePartenaires"];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"CellRecherchePartenaires"] autorelease];

                    }
    // Set up the cell...
    [[cell textLabel] setText: [tableViewArray objectAtIndex:indexPath.row]] ;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tabelViewCivilite deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    self.civiliteInputString = selectedCell.textLabel.text;

    [tableView  reloadData];

}

当我从 Class Number1 转到 Class Number2 时,它可以工作。当我从Class Number2返回到Class Number1时,我在Class Number2中得到EXC_BAD_ACCESS,在这一行:

[super dealloc];

Any想法 为什么?

I have the following:

Class Number1

.h file:

myAudiCiviliteInputViewController *civiliteInputViewController;

.m file:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableViewEtape4 deselectRowAtIndexPath:indexPath animated:NO];

    civiliteInputViewController = [[myAudiCiviliteInputViewController alloc] init];
    [self.navigationController pushViewController:civiliteInputViewController animated:YES];
    [civiliteInputViewController release];

    UIButton* customView = [UIButton buttonWithType: UIButtonTypeInfoLight];
    [customView setFrame:CGRectMake(0, 0, 60, 31)];
    [customView setImage:[UIImage imageNamed:@"nc_btn_ok.png"] forState:UIControlStateNormal];
    [customView addTarget:self action:@selector(okPressed) forControlEvents:UIControlEventTouchDown];
    UIBarButtonItem *envoyerButton = [[UIBarButtonItem alloc] initWithCustomView: customView];
    [self.navigationController.navigationBar.topItem setRightBarButtonItem:envoyerButton];
    [customView release];

}

-(void) okPressed{

        self.civiliteString= civiliteInputViewController.civiliteInputString;
        civiliteLabel.text = self.civiliteString;

        [self.navigationController popViewControllerAnimated:YES];
}

When I click the tableView I move onto class Number 2.

Class Number2 myAudiCiviliteInputViewController

@synthesize civiliteInputString;

- (void)dealloc
{
    [civiliteInputString release];
    [tabelViewCivilite release];
    [tableViewArray release];
    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    tableViewArray = [[NSMutableArray alloc] initWithObjects:@"Madame", @"Mademoiselle", @"Monsieur", nil];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellRecherchePartenaires"];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"CellRecherchePartenaires"] autorelease];

                    }
    // Set up the cell...
    [[cell textLabel] setText: [tableViewArray objectAtIndex:indexPath.row]] ;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tabelViewCivilite deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    self.civiliteInputString = selectedCell.textLabel.text;

    [tableView  reloadData];

}

When I go from Class Number1 to Class Number2 it works. When I come back from Class Number2 to Class Number1 I get EXC_BAD_ACCESS in Class Number2, at this line:

[super dealloc];

Any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时间你老了 2024-12-15 23:49:31

看看你的代码。 UIButton* customView 是自动释放的。删除-> [自定义视图发布]

UIButton* customView = [UIButton buttonWithType: UIButtonTypeInfoLight];
[customView setFrame:CGRectMake(0, 0, 60, 31)];
[customView setImage:[UIImage imageNamed:@"nc_btn_ok.png"] forState:UIControlStateNormal];
[customView addTarget:self action:@selector(okPressed) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *envoyerButton = [[UIBarButtonItem alloc] initWithCustomView: customView];
[self.navigationController.navigationBar.topItem setRightBarButtonItem:envoyerButton];
[customView release]; // Remove this line

Looking at your code. UIButton* customView is autoreleased. Remove -> [customView release]

UIButton* customView = [UIButton buttonWithType: UIButtonTypeInfoLight];
[customView setFrame:CGRectMake(0, 0, 60, 31)];
[customView setImage:[UIImage imageNamed:@"nc_btn_ok.png"] forState:UIControlStateNormal];
[customView addTarget:self action:@selector(okPressed) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *envoyerButton = [[UIBarButtonItem alloc] initWithCustomView: customView];
[self.navigationController.navigationBar.topItem setRightBarButtonItem:envoyerButton];
[customView release]; // Remove this line
瞄了个咪的 2024-12-15 23:49:31
  1. 您不应该release customView,因为它是自动释放的,删除:[customView release];

  2. 你应该release envoyerButton,添加: [envoyerButton release];

  1. You shouldn't release customView as it is autoreleased, remove : [customView release];

  2. You should release envoyerButton, add : [envoyerButton release];

远昼 2024-12-15 23:49:31

.h 文件

myAudiCiviliteInputViewController *civiliteInputViewController;

.m 文件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

[tableViewEtape4 deselectRowAtIndexPath:indexPath animated:NO];
civiliteInputViewController = [[myAudiCiviliteInputViewController alloc] init];
[self.navigationController pushViewController:civiliteInputViewController animated:YES];
[civiliteInputViewController release];

UIButton* customView = [UIButton buttonWithType: UIButtonTypeInfoLight]; // Autoreleasing object 
[customView setFrame:CGRectMake(0, 0, 60, 31)];
[customView setImage:[UIImage imageNamed:@"nc_btn_ok.png"] forState:UIControlStateNormal];
[customView addTarget:self action:@selector(okPressed) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *envoyerButton = [[UIBarButtonItem alloc] initWithCustomView: customView];
[self.navigationController.navigationBar.topItem setRightBarButtonItem:envoyerButton];
[envoyerButton release]; // You should release this object
}

-(void) okPressed
{

    self.civiliteString= civiliteInputViewController.civiliteInputString;
    civiliteLabel.text = self.civiliteString;

    [self.navigationController popViewControllerAnimated:YES];
 }

.h file

myAudiCiviliteInputViewController *civiliteInputViewController;

.m file

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

[tableViewEtape4 deselectRowAtIndexPath:indexPath animated:NO];
civiliteInputViewController = [[myAudiCiviliteInputViewController alloc] init];
[self.navigationController pushViewController:civiliteInputViewController animated:YES];
[civiliteInputViewController release];

UIButton* customView = [UIButton buttonWithType: UIButtonTypeInfoLight]; // Autoreleasing object 
[customView setFrame:CGRectMake(0, 0, 60, 31)];
[customView setImage:[UIImage imageNamed:@"nc_btn_ok.png"] forState:UIControlStateNormal];
[customView addTarget:self action:@selector(okPressed) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *envoyerButton = [[UIBarButtonItem alloc] initWithCustomView: customView];
[self.navigationController.navigationBar.topItem setRightBarButtonItem:envoyerButton];
[envoyerButton release]; // You should release this object
}

-(void) okPressed
{

    self.civiliteString= civiliteInputViewController.civiliteInputString;
    civiliteLabel.text = self.civiliteString;

    [self.navigationController popViewControllerAnimated:YES];
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文