Ios 正在检索未查看的UITableViewCells的数据源

Ios 正在检索未查看的UITableViewCells的数据源,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITableView,它显示了以xml形式接收的元素,然后将这些元素分为节和行。我使用indexPathsForVisibleRows跟踪屏幕上显示的元素,并将其保存到NSMutableSet中: @interface MainFeedTableViewController () <UIGestureRecognizerDelegate> { NSMutableSet *viewedCellsIndexPaths; } @end 但我收到一个异常[\uu NSSe

我有一个UITableView,它显示了以xml形式接收的元素,然后将这些元素分为节和行。我使用indexPathsForVisibleRows跟踪屏幕上显示的元素,并将其保存到NSMutableSet中:

@interface MainFeedTableViewController () <UIGestureRecognizerDelegate>
{
    NSMutableSet *viewedCellsIndexPaths;
}
@end
但我收到一个异常[\uu NSSetM lastObject]:无法识别的选择器发送到实例0x2837acb2

听起来好像我想不出解决的办法

我的最后一次尝试是:

但在迭代之后,unViewedCellsData与sectionOrderedFeed完全相同


有人帮忙吗

以下是我做的快速测试:

@interface ViewedCellsTableViewController ()
{
    NSMutableArray *myData;
    NSMutableSet *viewedCellsIndexPaths;
    NSMutableOrderedSet *orderedAllIndexPaths;
}

@end

@implementation ViewedCellsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // just creating sample data...
    //  6 sections with a few rows in each section
    NSArray *rowsPerSection = @[@3, @5, @4, @8, @6, @7];

    myData = [NSMutableArray new];
    int iSection = 0;
    for (NSNumber *nRows in rowsPerSection) {
        NSMutableArray *aSec = [NSMutableArray new];
        for (int iRow = 0; iRow < [nRows intValue]; iRow++) {
            NSString *s = [NSString stringWithFormat:@"This is sec: %d row:%d", iSection, iRow];
            [aSec addObject:s];
        }
        [myData addObject:aSec];
        ++iSection;
    }

    // initialize ordered set of all index paths
    orderedAllIndexPaths = [NSMutableOrderedSet new];
    iSection = 0;
    for (NSArray *aSec in myData) {
        for (int iRow = 0; iRow < [aSec count]; iRow++) {
            NSIndexPath *p = [NSIndexPath indexPathForRow:iRow inSection:iSection];
            [orderedAllIndexPaths addObject:p];
        }
        ++iSection;
    }

    // init tracking set
    viewedCellsIndexPaths = [NSMutableSet new];

}

以下是我为快速测试所做的:

@interface ViewedCellsTableViewController ()
{
    NSMutableArray *myData;
    NSMutableSet *viewedCellsIndexPaths;
    NSMutableOrderedSet *orderedAllIndexPaths;
}

@end

@implementation ViewedCellsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // just creating sample data...
    //  6 sections with a few rows in each section
    NSArray *rowsPerSection = @[@3, @5, @4, @8, @6, @7];

    myData = [NSMutableArray new];
    int iSection = 0;
    for (NSNumber *nRows in rowsPerSection) {
        NSMutableArray *aSec = [NSMutableArray new];
        for (int iRow = 0; iRow < [nRows intValue]; iRow++) {
            NSString *s = [NSString stringWithFormat:@"This is sec: %d row:%d", iSection, iRow];
            [aSec addObject:s];
        }
        [myData addObject:aSec];
        ++iSection;
    }

    // initialize ordered set of all index paths
    orderedAllIndexPaths = [NSMutableOrderedSet new];
    iSection = 0;
    for (NSArray *aSec in myData) {
        for (int iRow = 0; iRow < [aSec count]; iRow++) {
            NSIndexPath *p = [NSIndexPath indexPathForRow:iRow inSection:iSection];
            [orderedAllIndexPaths addObject:p];
        }
        ++iSection;
    }

    // init tracking set
    viewedCellsIndexPaths = [NSMutableSet new];

}

您在哪里调用
trackVisibleCells
?在测试代码时,我在类型为“NSMutableSet*”的对象上找到了
属性“lastObject”,该属性位于
NSIndexPath*lastIndex=(NSIndexPath*)ViewedCellsIndexPath.lastObject
这是正常的(崩溃就是这么说的)。@Larme,正如我上面所说的,我尝试将
viewedCellsIndexPaths
类型更改为
SensorDeredMutableSet
在尝试这一行之前,您可能错过了它@DonMag
trackVisibleCells
在表加载完成后立即被调用您在哪里调用
trackVisibleCells
?在测试代码时,我在
NSIndexPath*lastIndex=(NSIndexPath*)viewedCellsIndexPaths.lastObject上的类型为“NSMutableSet*”的对象上找不到属性“lastObject”
这是正常的(崩溃就是这么说的)。@Larme,正如我上面所说的,我尝试将
viewedCellsIndexPaths
类型更改为
SensorDeredMutableSet
在尝试这一行之前,您可能错过了它@DonMag
TrackVisibleCell
在表加载完成后立即被调用
NSIndexPath *lastIndex = (NSIndexPath *)viewedCellsIndexPaths.lastObject;
 NSMutableArray *unviewedCellsData = [NSMutableArray arrayWithArray:sectionOrderedFeed];
    for (NSIndexPath *indexPath in viewedCellsIndexPaths) {
        Items *item = [[sectionOrderedFeed objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        [unviewedCellsData removeObject:item];
    }
@interface ViewedCellsTableViewController ()
{
    NSMutableArray *myData;
    NSMutableSet *viewedCellsIndexPaths;
    NSMutableOrderedSet *orderedAllIndexPaths;
}

@end

@implementation ViewedCellsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // just creating sample data...
    //  6 sections with a few rows in each section
    NSArray *rowsPerSection = @[@3, @5, @4, @8, @6, @7];

    myData = [NSMutableArray new];
    int iSection = 0;
    for (NSNumber *nRows in rowsPerSection) {
        NSMutableArray *aSec = [NSMutableArray new];
        for (int iRow = 0; iRow < [nRows intValue]; iRow++) {
            NSString *s = [NSString stringWithFormat:@"This is sec: %d row:%d", iSection, iRow];
            [aSec addObject:s];
        }
        [myData addObject:aSec];
        ++iSection;
    }

    // initialize ordered set of all index paths
    orderedAllIndexPaths = [NSMutableOrderedSet new];
    iSection = 0;
    for (NSArray *aSec in myData) {
        for (int iRow = 0; iRow < [aSec count]; iRow++) {
            NSIndexPath *p = [NSIndexPath indexPathForRow:iRow inSection:iSection];
            [orderedAllIndexPaths addObject:p];
        }
        ++iSection;
    }

    // init tracking set
    viewedCellsIndexPaths = [NSMutableSet new];

}
NSMutableOrderedSet *unViewedCellsIndexPaths = [orderedAllIndexPaths mutableCopy];
[unViewedCellsIndexPaths minusSet:viewedCellsIndexPaths];

NSLog(@"\nViewed:\n%@ \n..", viewedCellsIndexPaths);
NSLog(@"");

NSLog(@"\nUn-Viewed:\n%@ \n..", unViewedCellsIndexPaths);
NSLog(@"");