简体   繁体   中英

Strange issue in iOS 8 UITableView

I've a UITableView with custom UITableViewCell in a Master-Detail structure. The cells of the table can be documents or folder...if a cell is a document, it opens the document in the detail view, but if is a folder it opens other cells below. This works perfectly on iOS 7, but running in iOS 8, when I tap a cell, my app freezes and it takes more and more memory...at the end it crashes. I've tried EVERYTHING...I've searched EVERYWHERE...nothing seems to work!!!

Here is my didSelectRowAtIndexPath: method

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"OBJECTS: %lu", (unsigned long)_objects.count);
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *d=[_objects objectAtIndex:indexPath.row];
    if([d valueForKey:@"Objects"])
    {
        NSArray *ar=[d valueForKey:@"Objects"];
        BOOL isAlreadyInserted=NO;
        for(NSDictionary *dInner in ar )
        {
            NSInteger index=[_objects indexOfObjectIdenticalTo:dInner];
            isAlreadyInserted=(index>0 && index!=NSIntegerMax);
            if(isAlreadyInserted) break;
        }
        if(isAlreadyInserted)
        {
            [self miniMizeThisRows:ar];
        }
        else
        {
            NSUInteger count=indexPath.row+1;
            NSMutableArray *arCells=[NSMutableArray array];
            for(NSDictionary *dInner in ar )
            {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                [_objects insertObject:dInner atIndex:count++];
            }

            [self addRowsAtIndexPaths:arCells];
        }
    }
    else
    {
        NSDictionary *object = [_objects objectAtIndex:indexPath.row];
        self.detailViewController.detailItem = [object objectForKey:@"name"];
        self.detailViewController.title = [object objectForKey:@"displayedName"];

        if(![cache containsObject:object])
        {
            TableCustomCell *cell = (TableCustomCell*)[tableView cellForRowAtIndexPath:indexPath];
            [cell.marker setHidden:NO];

            [cache addObject:object];
        }
    }
}

And in addRowsAtIndexPaths: I just do

- (void)addRowsAtIndexPaths:(NSArray*)indexPaths
{
    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
    [self.tableView endUpdates];
}

Someone helps???

Thank you.

EDIT

I figured out that the cycle is caused by my UITableViewCell sublcass... I used this code to manage the indentation:

- (void)layoutSubviews
{
    [super layoutSubviews];

    float indentPoints = self.indentationLevel * self.indentationWidth;

    self.contentView.frame = CGRectMake(indentPoints,
                                        self.contentView.frame.origin.y,
                                        self.contentView.frame.size.width - indentPoints,
                                        self.contentView.frame.size.height);
}

By commenting this, the app works...but the cells aren't indented!

Try to press 'Pause' button at debugger, during this freeze, and look on callStack, than, press 'Continue' button, and again 'Pause', and look for calls, witch of them is the same. It looks like call cycle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM