iPhone 上的 EXC_BAD_ACCESS
我有以下内容:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看你的代码。 UIButton* customView 是自动释放的。删除-> [自定义视图发布]
Looking at your code. UIButton* customView is autoreleased. Remove -> [customView release]
您不应该
release
customView
,因为它是自动释放的,删除:[customView release];
你应该
release
envoyerButton
,添加:[envoyerButton release];
You shouldn't
release
customView
as it is autoreleased, remove :[customView release];
You should
release
envoyerButton
, add :[envoyerButton release];
.h 文件
.m 文件
.h file
.m file