滚动时的NSTableView失真

时间:2013-08-20 15:00:28

标签: objective-c nstableview

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

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

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

任何帮助都非常感谢!

Distorted row on 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;
}

0 个答案:

没有答案