Overview
TableView is a native view component (UIView/NSView) that renders markdown tables with features including header rows, striped styling, grid borders, and interactive cell content. It uses GridView for visual rendering and TableViewCellManager for cell management.
Class Definition
Type Aliases
Properties
A 2D array representing table rows and columns. Each element is an
NSAttributedString with rich text formatting.This property is read-only. Use
setContents(_:) to update table data.Closure called when a link in a table cell is tapped.Parameters:
LinkPayload: Either.url(URL)or.string(String)NSRange: The range of the link in the cell textCGPoint: The tap location in MarkdownView coordinates
Returns the total number of rows in the table.
Returns the number of columns (based on the first row).
The calculated height of the table content.
Methods
Sets the table contents. Automatically processes Parameters:
<br> tags to newlines.contents: 2D array of attributed strings representing table cells
Updates the table’s visual theme.Parameters:
theme: The markdown theme to apply
Layout Configuration
Internal constants control the table layout:GridView
Overview
GridView renders the visual grid structure including borders, header background, and alternating row stripes.
Properties
Padding around the grid.
Methods
Updates the grid dimensions with column widths and row heights.Parameters:
widths: Array of column widthsheights: Array of row heights
Applies theme colors to the grid (borders, backgrounds).
Enables or disables header row styling.
Visual Layers
The grid view uses multiple Core Animation layers:backgroundLayer: Base cell backgroundstripeLayer: Alternating row backgroundsheaderBackgroundLayer: First row backgroundshapeLayer: Border lines
TableViewCellManager
Overview
TableViewCellManager manages the creation, reuse, and layout of individual table cells.
Properties
Array of cell views.
Array of calculated cell sizes.
Array of column widths.
Array of row heights.
Methods
Configures cells for the given content. Performs diff-based updates for performance.Parameters:
contents: 2D array of cell contentscontainerView: Parent view to add cells tocellPadding: Internal cell paddingmaximumCellWidth: Maximum width constraint for cells
Updates the theme for all cells.
Sets the delegate for all cells (for link handling).
Theme Configuration
Tables use theMarkdownTheme.Table configuration:
Example Usage
Features
Header Row Styling
The first row is automatically styled as a header with:- Bold text
- Different background color
- Rounded top corners
Alternating Row Colors
Data rows (excluding header) have alternating background colors for better readability.Content Processing
<br> tags in cell content are automatically converted to newline characters.
Performance Optimization
The table manager uses diff-based updates:- Only changed cells are reconfigured
- Cell sizes are cached when layout constraints remain the same
- Content fingerprinting prevents unnecessary updates
Accessibility
accessibilityLabel: “Table, rows, columns”- Individual cells are selectable and accessible
- Proper VoiceOver navigation support
Related Components
- GridView - Grid rendering
- MarkdownTheme - Theme customization