#iphone #uitableview #exc-bad-access
#iPhone #uitableview #исключение -плохой доступ
Вопрос:
У меня есть следующее:
Номер класса 1
файл .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
.
Класс 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
, я вхожу EXC_BAD_ACCESS
в Class Number2
эту строку:
[super dealloc];
Есть идеи, почему?
Комментарии:
1. Что такое tableViewCivilite в классе номер 2? Почему вы его выпускаете, я не вижу никакого выделения, создания, создания или копирования.
Ответ №1:
Смотрю на ваш код. 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
Ответ №2:
-
Вы не
release
customView
должны, поскольку он автоматически выпущен, удалять :[customView release];
-
Вы должны
release
envoyerButton
добавить :[envoyerButton release];
Ответ №3:
файл .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];
}