Skip to content

Instantly share code, notes, and snippets.

@woojooin
Created January 17, 2019 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woojooin/3b52da5e9c9fa8beef0f49246c0ed9ab to your computer and use it in GitHub Desktop.
Save woojooin/3b52da5e9c9fa8beef0f49246c0ed9ab to your computer and use it in GitHub Desktop.
TableView Usage
- (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