1

我有一个嵌入在 TabView 中的 NSTableView,我在滚动表格时看到一些奇怪的绘图扭曲,如下图所示。奇怪的是,我已经在这个项目上工作了一个多月,而这才刚刚开始。

我已经覆盖了行绘图代码,它也在下面,但几周没有改变。

最近唯一相当重要的变化是将项目更新到 XCode 5.0Dp,因为这个应用程序要等到 iOS7 发布后才会发布,我想确保一切正常(我做了一件好事,因为我有一些代码导致应用程序崩溃随附的 iOS 应用程序)。

非常感谢任何帮助!

NSTableView 上的扭曲行

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {

// Get a new ViewCell
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];

//Identify the correct column
if( [tableColumn.identifier isEqualToString:@"userLogo"] )
{
    Tweet* selectedTweet;
    if(self.updatingBucket == YES){

        NSFetchRequest *request = [[NSFetchRequest alloc] init];


    //Set predicate and filter for New tweets page
    if ([self.currentTwitterView isEqualToString:@"new"]) {
        NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"(approved == NO) AND (tweetDeleted == NO)  AND (scheduledTweet == NO)"];
        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"postDate" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
        [request setPredicate:testForTrue];
        [request setSortDescriptors:sortDescriptors];

    //Set filter and predicate for the Approved tweets page
    } else if ([self.currentTwitterView isEqualToString:@"approved"]){
        NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"(approved == YES) AND (tweetDeleted == NO)  AND (scheduledTweet == NO)"];
        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"approvedDate" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
        [request setPredicate:testForTrue];
        [request setSortDescriptors:sortDescriptors];

    //Set filter and preicate for the Deleted tweets page
    } else if ([self.currentTwitterView isEqualToString:@"deleted"]){
        NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"tweetDeleted == YES"];
        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"deletedDate" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
        [request setPredicate:testForTrue];
        [request setSortDescriptors:sortDescriptors];

    //Set filter and preicate for the Deleted tweets page
    } else if ([self.currentTwitterView isEqualToString:@"scheduled"]){
    NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"scheduledTweet == YES"];
    NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"scheduledDate" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
    [request setPredicate:testForTrue];
    [request setSortDescriptors:sortDescriptors];
    }


    //Setup the Request
    [request setEntity:[NSEntityDescription entityForName:@"Tweet" inManagedObjectContext:_managedObjectContext]];

    //Assign the predicate to the fetch request
    NSError *error = nil;

    //Create an array from the returned objects
    NSArray *fetchedObjects = [_managedObjectContext executeFetchRequest:request error:&error];

    selectedTweet = [fetchedObjects objectAtIndex:row];

      } else {


          selectedTweet = [self.onScreenTweets objectAtIndex:row];

      }


    cellView.imageView.image = nil;
    dispatch_async(dispatch_queue_create("getAsynchronIconsGDQueue", NULL),
                   ^{
                       NSURL *url = [NSURL URLWithString:selectedTweet.avatarUrl];
                       NSImage *image = [[NSImage alloc] initWithContentsOfURL:url];
                       cellView.imageView.image = image;
                   });

    //[cellView setWantsLayer:YES];
    return cellView;

}

编辑 1

这是表格行的绘图代码:

//Load the image into the table

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {

// Get a new ViewCell
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];

if(tableView == self.tweetTableView){

//Identify the correct column
if( [tableColumn.identifier isEqualToString:@"userLogo"] )
{
    Tweet* selectedTweet;
    if(self.updatingBucket == YES || self.facebookFetching == YES){

        NSFetchRequest *request = [[NSFetchRequest alloc] init];


    //Set predicate and filter for New tweets page
    if ([self.currentTwitterView isEqualToString:@"new"]) {
        NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"(approved == NO) AND (tweetDeleted == NO)  AND (scheduledTweet == NO)"];
        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"postDate" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
        [request setPredicate:testForTrue];
        [request setSortDescriptors:sortDescriptors];

    //Set filter and predicate for the Approved tweets page
    } else if ([self.currentTwitterView isEqualToString:@"approved"]){
        NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"(approved == YES) AND (tweetDeleted == NO)  AND (scheduledTweet == NO)"];
        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"approvedDate" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
        [request setPredicate:testForTrue];
        [request setSortDescriptors:sortDescriptors];

    //Set filter and preicate for the Deleted tweets page
    } else if ([self.currentTwitterView isEqualToString:@"deleted"]){
        NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"tweetDeleted == YES"];
        NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"deletedDate" ascending:NO];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
        [request setPredicate:testForTrue];
        [request setSortDescriptors:sortDescriptors];

    //Set filter and preicate for the Deleted tweets page
    } else if ([self.currentTwitterView isEqualToString:@"scheduled"]){
    NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"scheduledTweet == YES"];
    NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"scheduledDate" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
    [request setPredicate:testForTrue];
    [request setSortDescriptors:sortDescriptors];
    }


    //Setup the Request
    [request setEntity:[NSEntityDescription entityForName:@"Tweet" inManagedObjectContext:_managedObjectContext]];

    //Assign the predicate to the fetch request
    NSError *error = nil;

    //Create an array from the returned objects
    NSArray *fetchedObjects = [_managedObjectContext executeFetchRequest:request error:&error];

    selectedTweet = [fetchedObjects objectAtIndex:row];

      } else {


          selectedTweet = [self.onScreenTweets objectAtIndex:row];

      }


    cellView.imageView.image = nil;
    dispatch_async(dispatch_queue_create("getAsynchronIconsGDQueue", NULL),
                   ^{
                       NSURL *url = [NSURL URLWithString:selectedTweet.avatarUrl];
                       NSImage *image = [[NSImage alloc] initWithContentsOfURL:url];
                       cellView.imageView.image = image;
                   });


    //[cellView setWantsLayer:YES];
    return cellView;

} if([tableColumn.identifier isEqualToString:@"secondButtons"]){
    Tweet* selectedTweet;

    if(self.updatingBucket == YES){

        NSFetchRequest *request = [[NSFetchRequest alloc] init];


        //Set predicate and filter for New tweets page
        if ([self.currentTwitterView isEqualToString:@"new"]) {
            NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"(approved == NO) AND (tweetDeleted == NO)  AND (scheduledTweet == NO)"];
            NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"postDate" ascending:NO];
            NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
            [request setPredicate:testForTrue];
            [request setSortDescriptors:sortDescriptors];

            //Set filter and predicate for the Approved tweets page
        } else if ([self.currentTwitterView isEqualToString:@"approved"]){
            NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"(approved == YES) AND (tweetDeleted == NO)  AND (scheduledTweet == NO)"];
            NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"approvedDate" ascending:NO];
            NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
            [request setPredicate:testForTrue];
            [request setSortDescriptors:sortDescriptors];

            //Set filter and preicate for the Deleted tweets page
        } else if ([self.currentTwitterView isEqualToString:@"deleted"]){
            NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"tweetDeleted == YES"];
            NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"deletedDate" ascending:NO];
            NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
            [request setPredicate:testForTrue];
            [request setSortDescriptors:sortDescriptors];

            //Set filter and preicate for the Deleted tweets page
        } else if ([self.currentTwitterView isEqualToString:@"scheduled"]){
            NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"scheduledTweet == YES"];
            NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"scheduledDate" ascending:NO];
            NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, nil];
            [request setPredicate:testForTrue];
            [request setSortDescriptors:sortDescriptors];
        }


        //Setup the Request
        [request setEntity:[NSEntityDescription entityForName:@"Tweet" inManagedObjectContext:_managedObjectContext]];

        //Assign the predicate to the fetch request
        NSError *error = nil;

        //Create an array from the returned objects
        NSArray *fetchedObjects = [_managedObjectContext executeFetchRequest:request error:&error];

        selectedTweet = [fetchedObjects objectAtIndex:row];

    } else {


        selectedTweet = [self.onScreenTweets objectAtIndex:row];

    }

    if(selectedTweet.imageURL){

        //NSTableCellView *buttonCell = [tableView makeViewWithIdentifier:@"secondButtons" owner:self];
        //[buttonCell setHidden:NO];
        //return buttonCell;

    } else {

        //NSTableCellView *buttonCell = [tableView makeViewWithIdentifier:@"secondButtons" owner:self];
        //[buttonCell setHidden:YES];
        //return buttonCell;

    }


}

} else{
    NSTableCellView *cellView2 = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
    return cellView2;

}
//[cellView setWantsLayer:YES];
return cellView;
}
4

0 回答 0