简体   繁体   English

iOS 8 UITableView中的奇怪问题

[英]Strange issue in iOS 8 UITableView

I've a UITableView with custom UITableViewCell in a Master-Detail structure. 我有一个UITableView ,在Master-Detail结构中具有自定义UITableViewCell 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. 这在iOS 7上完美运行,但是在iOS 8上运行时,当我点击一个单元格时,我的应用程序冻结,并且占用了越来越多的内存...最后,它崩溃了。 I've tried EVERYTHING...I've searched EVERYWHERE...nothing seems to work!!! 我已经尝试了一切...我已经搜索了一切...似乎什么都没用!

Here is my didSelectRowAtIndexPath: method 这是我的didSelectRowAtIndexPath:方法

- (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 在addRowsAtIndexPaths中:

- (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: 我发现循环是由我的UITableViewCell sublcass引起的...我使用以下代码来管理缩进:

- (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. 在冻结期间,尝试在调试器上按“暂停”按钮,然后在callStack上查看,然后按“继续”按钮,再按“暂停”,然后查找调用,它们之间是一样的。 It looks like call cycle. 看起来像通话周期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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