Skip to content

Commit

Permalink
fixes issue #104: don't show separator if not showing search results …
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
Nicholas Solter committed Aug 3, 2015
1 parent 5a72d72 commit 66eafd9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions TITokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@
@property (nonatomic, assign) BOOL alwaysShowSearchResult;
@property (nonatomic, assign) BOOL shouldSortResults;
@property (nonatomic, assign) BOOL shouldSearchInBackground;
@property (nonatomic, assign) BOOL shouldAlwaysShowSeparator;
@property (nonatomic, assign) UIPopoverArrowDirection permittedArrowDirections;
@property (nonatomic, readonly) TITokenField * tokenField;
@property (nonatomic, readonly) UIView * separator;
@property (nonatomic, readonly) UIView * tableHeader;
@property (nonatomic, readonly) UITableView * resultsTable;
@property (nonatomic, readonly) UIView * contentView;
@property (nonatomic, copy) NSArray * sourceArray;
Expand Down
33 changes: 29 additions & 4 deletions TITokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ @implementation TITokenFieldView {
@synthesize alwaysShowSearchResult = _alwaysShowSearchResult;
@synthesize shouldSortResults = _shouldSortResults;
@synthesize shouldSearchInBackground = _shouldSearchInBackground;
@synthesize shouldAlwaysShowSeparator = _shouldAlwaysShowSeparator;
@synthesize permittedArrowDirections = _permittedArrowDirections;
@synthesize tokenField = _tokenField;
@synthesize resultsTable = _resultsTable;
@synthesize contentView = _contentView;
@synthesize separator = _separator;
@synthesize tableHeader = _tableHeader;
@synthesize sourceArray = _sourceArray;

#pragma mark Init
Expand Down Expand Up @@ -79,6 +81,7 @@ - (void)setup {
_alwaysShowSearchResult = NO;
_shouldSortResults = YES;
_shouldSearchInBackground = NO;
_shouldAlwaysShowSeparator = YES;
_permittedArrowDirections = UIPopoverArrowDirectionUp;
_resultsArray = [NSMutableArray array];

Expand All @@ -95,8 +98,12 @@ - (void)setup {

_separator = [[UIView alloc] initWithFrame:CGRectMake(0, tokenFieldBottom, self.bounds.size.width, 1)];
[_separator setBackgroundColor:[UIColor colorWithWhite:0.7 alpha:1]];
[self addSubview:_separator];


_tableHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 1)];
[_tableHeader setBackgroundColor:[UIColor colorWithWhite:0.7 alpha:1]];

[self addSubview:_separator];

// This view is created for convenience, because it resizes and moves with the rest of the subviews.
_contentView = [[UIView alloc] initWithFrame:CGRectMake(0, tokenFieldBottom + 1, self.bounds.size.width,
self.bounds.size.height - tokenFieldBottom - 1)];
Expand All @@ -111,7 +118,7 @@ - (void)setup {
[tableViewController setContentSizeForViewInPopover:CGSizeMake(400, 400)];

_resultsTable = tableViewController.tableView;
_popoverController = [[UIPopoverController alloc] initWithContentViewController:tableViewController];
}
else
Expand All @@ -127,7 +134,12 @@ - (void)setup {
_popoverController = nil;
}

[self bringSubviewToFront:_separator];
if (_shouldAlwaysShowSeparator) {
[self bringSubviewToFront:_separator];
} else {
_separator.hidden = YES;
_resultsTable.tableHeaderView = _tableHeader;
}
[self bringSubviewToFront:_tokenField];
[self updateContentSize];
}
Expand Down Expand Up @@ -178,6 +190,19 @@ - (void)setAlwaysShowSearchResult:(BOOL)alwaysShowSearchResult
if (_alwaysShowSearchResult) [self resultsForSearchString:_tokenField.text];
}

- (void) setShouldAlwaysShowSeparator:(BOOL)shouldAlwaysShowSeparator
{
_shouldAlwaysShowSeparator = shouldAlwaysShowSeparator;
if (_shouldAlwaysShowSeparator) {
_resultsTable.tableHeaderView = nil;
_separator.hidden = NO;
[self bringSubviewToFront:_separator];
} else {
_separator.hidden = YES;
_resultsTable.tableHeaderView = _tableHeader;
}
}

#pragma mark Event Handling
- (void)layoutSubviews {

Expand Down

0 comments on commit 66eafd9

Please sign in to comment.