更新: - [NSIndexPath行]:消息發送到釋放的實例0x895fe70一個Objective-C消息被在地址發送到解除分配的對象(殭屍):0xaa722d0
當我在設備運行我的應用程序和分析它說:
一個Objective-C消息被髮送到解除分配的對象(殭屍)在地址:0xaa722d0。
它顯示錯誤的:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int newRow = [indexPath row];
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row]: -1;
我是很新的目標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];
}
請使用GDB中的BT命令更新錯誤描述的問題。 – Tirth 2012-01-09 03:50:42
無論問題是什麼,只需添加一個[obj retain]調用就可以解決它。 – CodaFi 2012-01-09 03:51:01
在Xcode中運行分析。什麼/問題在哪裏?在控制檯中什麼是錯誤信息? – zaph 2012-01-09 04:12:13