Created
January 17, 2019 23:59
-
-
Save woojooin/3b52da5e9c9fa8beef0f49246c0ed9ab to your computer and use it in GitHub Desktop.
TableView Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView | |
{ | |
if(tableView == bookTableView) | |
return books.count; | |
return clips.count; | |
} | |
- (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row | |
{ | |
if(tableView == bookTableView) | |
{ | |
NSString* dir = books[row]; | |
NSString* path; | |
BOOL bFavorRoot = [dir isEqualToString:FAVORITE_ROOT]; | |
if(bFavorRoot) | |
path = _appDelegate.favoritesPath; | |
else | |
path = [_appDelegate.favoritesPath stringByAppendingPathComponent:dir]; | |
NSTableCellView* cellView = [tableView makeViewWithIdentifier:@"imageTextCellView" owner:self]; | |
cellView.imageView.image = [NSImage imageNamed:@"folder"];//[[NSWorkspace sharedWorkspace] iconForFile:path]; | |
cellView.textField.stringValue = bFavorRoot ? @"Default" : dir; | |
cellView.textField.font = [NSFont boldSystemFontOfSize:13]; | |
return cellView; | |
} | |
ClipData* cdata = clips[row]; | |
if([tableView.tableColumns objectAtIndex:0] == tableColumn) | |
{ | |
NSTableCellView* cellView = [tableView makeViewWithIdentifier:@"imageTextCellView" owner:self]; | |
cellView.imageView.image = cdata.image!=nil ? cdata.image : [cdata typeImage]; | |
cellView.textField.stringValue = cdata.title; | |
cellView.textField.font = [NSFont boldSystemFontOfSize:12]; | |
return cellView; | |
} | |
else | |
{ | |
NSTableCellView* cellView = [tableView makeViewWithIdentifier:@"textCellView" owner:self]; | |
cellView.textField.stringValue = cdata.string!=nil ? cdata.string : TEXT(@"No String Data"); | |
return cellView; | |
} | |
} | |
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification | |
{ | |
[self updateControls]; | |
if(aNotification.object == bookTableView) | |
{ | |
[self reloadClips]; | |
return; | |
} | |
if(clipTableView.selectedRow == -1) | |
{ | |
_selItem = nil; | |
_selIndex = -1; | |
return; | |
} | |
_selItem = clips[clipTableView.selectedRow]; | |
_selIndex = clipTableView.selectedRow; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment