Skip to content

Commit

Permalink
Add proper specifier for some properties
Browse files Browse the repository at this point in the history
  • Loading branch information
matrush committed Jul 9, 2020
1 parent ebc186d commit 33274a6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 27 deletions.
Expand Up @@ -8,12 +8,22 @@

#import <UIKit/UIKit.h>

@class FLEXDBQueryRowCell;

extern NSString * const kFLEXDBQueryRowCellReuse;

@protocol FLEXDBQueryRowCellLayoutSource <NSObject>

- (CGFloat)dbQueryRowCell:(FLEXDBQueryRowCell *)dbQueryRowCell minXForColumn:(NSUInteger)column;
- (CGFloat)dbQueryRowCell:(FLEXDBQueryRowCell *)dbQueryRowCell widthForColumn:(NSUInteger)column;

@end

@interface FLEXDBQueryRowCell : UITableViewCell

/// An array of NSString, NSNumber, or NSData objects
@property (nonatomic) NSArray *data;
@property (nonatomic, strong) NSArray *data;

@property (nonatomic, readwrite, nullable, weak) id<FLEXDBQueryRowCellLayoutSource> layoutSource;

@end
Expand Up @@ -62,12 +62,13 @@ - (void)setColumnCount:(NSInteger)columnCount {

- (void)layoutSubviews {
[super layoutSubviews];

CGFloat width = self.contentView.frame.size.width / self.labels.count;

CGFloat height = self.contentView.frame.size.height;

[self.labels flex_forEach:^(UILabel *label, NSUInteger i) {
label.frame = CGRectMake(width * i + 5, 0, (width - 10), height);
CGFloat width = [_layoutSource dbQueryRowCell:self widthForColumn:i];
CGFloat minX = [_layoutSource dbQueryRowCell:self minXForColumn:i];
label.frame = CGRectMake(minX + 5, 0, (width - 10), height);
}];
}

Expand Down
Expand Up @@ -29,7 +29,7 @@
- (NSString *)rowTitle:(NSInteger)row;
- (NSArray<NSString *> *)contentForRow:(NSInteger)row;

- (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView widthForContentCellInColumn:(NSInteger)column;
- (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView minWidthForContentCellInColumn:(NSInteger)column;
- (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView heightForContentCellInRow:(NSInteger)row;
- (CGFloat)heightForTopHeaderInTableView:(FLEXMultiColumnTableView *)tableView;
- (CGFloat)widthForLeftHeaderInTableView:(FLEXMultiColumnTableView *)tableView;
Expand Down
Expand Up @@ -12,7 +12,7 @@
#import "FLEXColor.h"

@interface FLEXMultiColumnTableView () <
UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate
UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, FLEXDBQueryRowCellLayoutSource
>

@property (nonatomic) UIScrollView *contentScrollView;
Expand All @@ -25,8 +25,6 @@ @interface FLEXMultiColumnTableView () <
@property (nonatomic) NSInteger sortColumn;
@property (nonatomic) FLEXTableColumnHeaderSortType sortType;

@property (nonatomic) NSArray *rowData;

@property (nonatomic, readonly) NSInteger numberOfColumns;
@property (nonatomic, readonly) NSInteger numberOfRows;
@property (nonatomic, readonly) CGFloat topHeaderHeight;
Expand All @@ -38,6 +36,9 @@ @interface FLEXMultiColumnTableView () <
static const CGFloat kColumnMargin = 1;

@implementation FLEXMultiColumnTableView
{
NSArray<UIView *> *_headers;
}

#pragma mark - Initialization

Expand Down Expand Up @@ -71,9 +72,9 @@ - (void)layoutSubviews {
}

CGFloat contentWidth = 0.0;
NSInteger rowsCount = self.numberOfColumns;
for (int i = 0; i < rowsCount; i++) {
contentWidth += [self contentWidthForColumn:i];
NSInteger columnsCount = self.numberOfColumns;
for (int i = 0; i < columnsCount; i++) {
contentWidth += CGRectGetWidth(_headers[i].bounds);
}

CGFloat contentHeight = height - topheaderHeight - topInsets;
Expand Down Expand Up @@ -105,7 +106,7 @@ - (void)loadHeaderScrollView {
headerScrollView.delegate = self;
headerScrollView.backgroundColor = FLEXColor.secondaryGroupedBackgroundColor;
self.headerScrollView = headerScrollView;

[self addSubview:headerScrollView];
}

Expand Down Expand Up @@ -147,26 +148,25 @@ - (void)loadLeftView {
#pragma mark - Data

- (void)reloadData {
[self loadHeaderData];
[self loadLeftViewData];
[self loadContentData];
[self loadHeaderData];
}

- (void)loadHeaderData {
// Remove existing headers, if any
for (UIView *subview in self.headerScrollView.subviews) {
[subview removeFromSuperview];
}
NSMutableArray<UIView *> *headers = [NSMutableArray array];

CGFloat xOffset = 0.0;
for (NSInteger column = 0; column < self.numberOfColumns; column++) {
CGFloat width = [self contentWidthForColumn:column] + self.columnMargin;

FLEXTableColumnHeader *header = [[FLEXTableColumnHeader alloc]
initWithFrame:CGRectMake(xOffset, 0, width, self.topHeaderHeight - 1)
];
FLEXTableColumnHeader *header = [[FLEXTableColumnHeader alloc] initWithFrame:CGRectZero];
header.titleLabel.text = [self columnTitle:column];

CGFloat width = MAX([self minContentWidthForColumn:column], [header sizeThatFits:CGSizeMake(CGFLOAT_MAX, self.topHeaderHeight - 1)].width) + self.columnMargin;
header.frame = CGRectMake(xOffset, 0, width, self.topHeaderHeight - 1);

if (column == self.sortColumn) {
header.sortType = self.sortType;
}
Expand All @@ -179,8 +179,10 @@ - (void)loadHeaderData {
header.userInteractionEnabled = YES;

[self.headerScrollView addSubview:header];
[headers addObject:header];
xOffset += width;
}
_headers = [headers copy];
}

- (void)contentHeaderTap:(UIGestureRecognizer *)gesture {
Expand Down Expand Up @@ -227,13 +229,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
// Right side table view for data
else {
self.rowData = [self.dataSource contentForRow:indexPath.row];
FLEXDBQueryRowCell *cell = [tableView
dequeueReusableCellWithIdentifier:kFLEXDBQueryRowCellReuse forIndexPath:indexPath
];

cell.contentView.backgroundColor = backgroundColor;
cell.data = [self.dataSource contentForRow:indexPath.row];
cell.layoutSource = self;
NSAssert(cell.data.count == self.numberOfColumns, @"Count of data provided was incorrect");
return cell;
}
Expand Down Expand Up @@ -280,6 +282,17 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}


#pragma mark FLEXDBQueryRowCellLayoutSource

- (CGFloat)dbQueryRowCell:(FLEXDBQueryRowCell *)dbQueryRowCell minXForColumn:(NSUInteger)column {
return CGRectGetMinX(_headers[column].frame);
}

- (CGFloat)dbQueryRowCell:(FLEXDBQueryRowCell *)dbQueryRowCell widthForColumn:(NSUInteger)column {
return CGRectGetWidth(_headers[column].bounds);
}


#pragma mark DataSource Accessor

- (NSInteger)numberOfRows {
Expand All @@ -298,8 +311,8 @@ - (NSString *)rowTitle:(NSInteger)row {
return [self.dataSource rowTitle:row];
}

- (CGFloat)contentWidthForColumn:(NSInteger)column {
return [self.dataSource multiColumnTableView:self widthForContentCellInColumn:column];
- (CGFloat)minContentWidthForColumn:(NSInteger)column {
return [self.dataSource multiColumnTableView:self minWidthForContentCellInColumn:column];
}

- (CGFloat)contentHeightForRow:(NSInteger)row {
Expand Down
Expand Up @@ -11,6 +11,9 @@
#import "UIFont+FLEX.h"
#import "FLEXUtility.h"

static const CGFloat kMargin = 5.0f;
static const CGFloat kArrowWidth = 20.0f;

@interface FLEXTableColumnHeader ()
@property (nonatomic, readonly) UILabel *arrowLabel;
@property (nonatomic, readonly) UIView *lineView;
Expand Down Expand Up @@ -60,9 +63,14 @@ - (void)layoutSubviews {

CGSize size = self.frame.size;

self.titleLabel.frame = CGRectMake(5, 0, size.width - 25, size.height);
self.arrowLabel.frame = CGRectMake(size.width - 20, 0, 20, size.height);
self.titleLabel.frame = CGRectMake(kMargin, 0, size.width - kArrowWidth - kMargin, size.height);
self.arrowLabel.frame = CGRectMake(size.width - kArrowWidth, 0, kArrowWidth, size.height);
self.lineView.frame = CGRectMake(size.width - 1, 2, FLEXPointsToPixels(1), size.height - 4);
}

- (CGSize)sizeThatFits:(CGSize)size {
CGFloat width = [_titleLabel sizeThatFits:CGSizeMake(size.width - kArrowWidth - 2 * kMargin, size.height)].width + kArrowWidth + 2 * kMargin;
return CGSizeMake(width, size.height);
}

@end
Expand Up @@ -7,6 +7,7 @@
//

#import "FLEXTableContentViewController.h"
#import "FLEXTableRowViewController.h"
#import "FLEXMultiColumnTableView.h"
#import "FLEXWebViewController.h"
#import "FLEXUtility.h"
Expand Down Expand Up @@ -84,7 +85,7 @@ - (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView
}

- (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView
widthForContentCellInColumn:(NSInteger)column {
minWidthForContentCellInColumn:(NSInteger)column {
return 120;
}

Expand All @@ -107,10 +108,13 @@ - (CGFloat)widthForLeftHeaderInTableView:(FLEXMultiColumnTableView *)tableView {
#pragma mark MultiColumnTableView Delegate

- (void)multiColumnTableView:(FLEXMultiColumnTableView *)tableView didSelectRow:(NSInteger)row {
UIViewController *resultsScreen = [[FLEXTableRowViewController alloc] initWithTitle:[NSString stringWithFormat:@"Row %@", @(row)]
row:[[NSDictionary alloc] initWithObjects:self.rows[row] forKeys:self.columns]];
[self.navigationController pushViewController:resultsScreen animated:YES];
return;
NSArray<NSString *> *fields = [self.rows[row] flex_mapped:^id(NSString *field, NSUInteger idx) {
return [NSString stringWithFormat:@"%@:\n%@", self.columns[idx], field];
}];

[FLEXAlert makeAlert:^(FLEXAlert *make) {
make.title([@"Row " stringByAppendingString:@(row).stringValue]);
NSString *message = [fields componentsJoinedByString:@"\n\n"];
Expand Down

0 comments on commit 33274a6

Please sign in to comment.