簡體   English   中英

為什么我的應用程序因以下錯誤而崩潰?

[英]Why does my application crash with the following error?

當我上下滾動表視圖時,大約6-8次后,我的應用程序崩潰了,並且在調試窗口中得到了以下信息:

myapp[250:207] *** -[NSIndexPath row]: message sent to deallocated instance 0xdd0eab0

這是我的代碼:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [remoteRecipientItems count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"RemoteRecipientItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }




    NSUInteger row = [indexPath row];

    NSUInteger oldRow = [lastIndexPath row];

    // Configure the cell...

    [[cell textLabel]setText:[remoteRecipientItems objectAtIndex:[indexPath row]]];

    cell.accessoryType = (row == oldRow && lastIndexPath !=nil)? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; 

    return cell;
}





#pragma mark -
#pragma mark Table view delegate

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



    int newRow = [indexPath row];
    int oldRow = (lastIndexPath !=nil)?[lastIndexPath row]:-1;

    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];


}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;


    remoteRecipientItems = nil;
    remoteRecipientID = nil;
    xmlData = nil;
    lastIndexPath = nil;

}


- (void)dealloc {

    [remoteRecipientItems release];
    [remoteRecipientID release];
    [xmlData release];

    [lastIndexPath release];

    [super dealloc];
}

您不擁有indexPath變量,因此需要保留它。

嘗試替換此:

lastIndexPath = indexPath;

有了這個:

lastIndexPath = [indexPath retain];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM