Обновление: - [строка NSIndexPath]: сообщение отправлено освобожденному экземпляру 0x895fe70
Когда я запускаю свое приложение на устройстве и анализирую, он говорит:
Сообщение Objective C было отправлено освобожденному объекту (зомби) по адресу: 0xaa722d0.
Отображается ошибка в:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row]: -1;
Я очень новичок в программировании на Objective C и уже два дня бьюсь над этой проблемой. Недавно я создал приложение, использующее Xcode 3.2.6, но обновил его до Xcode 4 два дня назад и теперь сталкиваюсь с проблемами освобождения памяти, описанными ниже. код. Я исследовал использование инструментов и включил зомби и понял, где проблема возникает, но просто не смог ее решить,
Я прошу некоторые инструкции, пожалуйста .. ниже мой код запускается в Xcode 4.2.
#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [list count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CheckMarkCellIdentifier = @"CheckMarkCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
CheckMarkCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CheckMarkCellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSUInteger oldRow = [lastIndexPath row];
cell.textLabel.text = [list objectAtIndex:row];
cell.accessoryType = (row == oldRow && lastIndexPath != nil) ?
UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;
}
#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row]: -1;
//----Captures the value selected in the list and shown in parent view.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
SchneiderBMSAppDelegate *appDelegate = (SchneiderBMSAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.priorityValue = cell.textLabel.text;
NSLog(@"Product selected is: %@",appDelegate.priorityValue);
if (newRow != oldRow)
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:
indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:
lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)viewDidUnload {
self.list = nil;
self.lastIndexPath = nil;
[super viewDidUnload];
}
- (void)dealloc {
[list release];
[lastIndexPath release];
[super dealloc];
}