2014-12-16 2 views
0

У меня проблема с перекрывающимися рядами при прокрутке в таблице. Данные отображаются правильно, но при прокрутке вниз текст в строках перекрывается текстом из других строк.NSTableView перекрывающиеся строки при прокрутке

Вот код для создания NStableView:

-(void)addTableAt:(NSRect)rect withIdentifier:(NSString *)identifier withIndex:(int) index 
{ 
    // Get the table 
    if ([identifier isEqualToString:@"table_0"]) { 
     // The view 
     view = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, rect.size.width,rect.size.height)]; 
    } 

    // The ScrollView for the table 
    NSScrollView *tableScrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(index*rect.size.width, 0.0, rect.size.width, rect.size.height)]; 

    // The table view 
    NSTableView *tableView = [[NSTableView alloc] initWithFrame:NSMakeRect(index*rect.size.width, 0.0, rect.size.width, rect.size.height)]; 
    [tableView setIdentifier:identifier]; 
    [tableView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 
    [tableView setHeaderView:nil]; 

    // Set up the right click menu 
    NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"]; 
    NSString *menuString = [NSString stringWithFormat:@"%@_%d", @"table", index]; 
    NSMenuItem *menuItem = [theMenu insertItemWithTitle:@"Submit to Restore" action:@selector(fileRestore:) keyEquivalent:menuString atIndex:0]; 
    [menuItem setEnabled:YES]; 
    [menuItem setTarget:self]; 
    [tableView setMenu:theMenu]; 

    // Set the column 
    NSTableColumn *column =[[NSTableColumn alloc]initWithIdentifier:identifier]; 
    [column.headerCell setTitle:@"Header Title"]; 
    [column setWidth:245]; 

    // Add the column tot he table 
    [tableView addTableColumn:column]; 

    // Set the source and the delegate 
    [tableView setDataSource:self]; 
    [tableView setDelegate:self]; 
    [tableView setAllowsMultipleSelection: YES]; 

    // Add the table to the scroll view 
    [tableScrollView setDocumentView:tableView]; 

    // Create the view and the table scroll view 
    [view setFrame:NSMakeRect(0.0, 0.0, (index+1)*rect.size.width, rect.size.height)]; 
    [view addSubview:tableScrollView]; 

    // Set the view into the main scroll view 
    [main_scrollview setDocumentView:view]; 

    // Add the main scroll view to the main view 
    [main_view addSubview:main_scrollview]; 
    [main_view setNeedsDisplay:YES]; 
} 

Любые идеи о том, как это исправить?

ответ

-1

Не пытайтесь создавать NSTableView программно.

Используйте Interface Builder и используйте встроенный вид таблицы, заключенный в прокрутку. Интерфейс Builder -> Инструменты -> Библиотека -> Объекты "NSTableView в NSScrollView"

Слишком много вещей, которые необходимо подключить в правильном порядке.

Похоже, вам нужно добавить несколько таблиц в свое приложение? Если это так, вы можете создать несколько экземпляров, повторно используя nib несколько раз.

Здесь приведен пример кода примера для класса контроллера, который я использую в качестве шаблона для создания нескольких экземпляров наконечника. (детали, как управление окном/вида остаются вне ... это просто шаблон скелета)

В этом случае CHelpText мой контроллер, и мой СИБ назван CHelpText.xib

@interface CHelpText : NSWindowController { 
    IBOutlet NSTextView *mTextView; 
    IBOutlet NSView *mTransparentView; 
    NSArray    *mTopLevelObjects; 
} 
@property(retain) NSArray    *mTopLevelObjects; 

+(void)showHelp:(NSString *)iHelpText 
      title:(NSString *)iHelpTitle; 
-(void)awakeFromNib; 
- (IBAction) closeWindow: (id)sender 
@end 


@implementation CHelpText 
@synthesize mTopLevelObjects; 
+(void)showHelp:(NSString *)iHelpText 
      title:(NSString *)iHelpTitle 
{ 
    ////////////// BUILD CHelpText ///////////////////////////////// 
    NSBundle *theClassBundle; 
    theClassBundle = [NSBundle mainBundle]; 
    NSNib *theNib = [[NSNib alloc] initWithNibNamed:@"CHelpText" bundle:theClassBundle]; 
    CHelpText *theController = [CHelpText alloc]; 

    NSArray *theTopLevelObjects; 
    [theNib instantiateNibWithOwner:theController 
        topLevelObjects:&theTopLevelObjects]; 
    theController.mTopLevelObjects = theTopLevelObjects; 
    [theNib autorelease]; 
} 

-(void)awakeFromNib 
{ 
    if ([[self superclass] instancesRespondToSelector:@selector(awakeFromNib)]) 
     [super awakeFromNib]; 
} 

- (IBAction) closeWindow: (id)sender 
{ 
    [[self window] performClose:self]; 
    self.mTopLevelObjects = nil; 
    [self autorelease]; 
} 
+0

Спасибо, что было очень полезно. – frangieh

Смежные вопросы