Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Classes/PFNavigationDropdownMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@
title:(NSString *)title
items:(NSArray *)items
containerView:(UIView *)containerView;

// Open/Close State
- (void)openMenu;
- (void)closeMenu;
- (BOOL)isOpen;

// Item Selection
- (void)selectItemAtIndex:(NSUInteger)index;

@end
32 changes: 31 additions & 1 deletion Classes/PFNavigationDropdownMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ - (instancetype)initWithFrame:(CGRect)frame
__weak typeof(self) weakSelf = self;
self.tableView.selectRowAtIndexPathHandler = ^(NSUInteger indexPath){
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.didSelectItemAtIndexHandler(indexPath);
if (strongSelf.didSelectItemAtIndexHandler)
{
strongSelf.didSelectItemAtIndexHandler(indexPath);
}
[strongSelf setMenuTitleText:items[indexPath]];
[strongSelf hideMenu];
strongSelf.isShown = NO;
Expand Down Expand Up @@ -195,6 +198,33 @@ - (void)menuButtonTapped:(UIButton *)sender
}
}

#pragma mark - Open/Close State
- (void)openMenu
{
self.isShown = YES;
[self showMenu];
}

- (void)closeMenu
{
self.isShown = NO;
[self hideMenu];
}

- (BOOL)isOpen
{
return [self isShown];
}

#pragma mark - Item Selection
- (void)selectItemAtIndex:(NSUInteger)index
{
if (index >= self.items.count) {
index = self.items.count - 1;
}
[self.tableView selectIndex:index];
}

#pragma mark - Setters
- (void)setCellHeight:(CGFloat)cellHeight
{
Expand Down
4 changes: 4 additions & 0 deletions Classes/PFTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
@property (nonatomic, copy) void(^selectRowAtIndexPathHandler)(NSUInteger indexPath);

- (instancetype)initWithFrame:(CGRect)frame items:(NSArray *)items configuration:(PFConfiguration *)configuration;

// Setters
- (void)selectIndex:(NSUInteger)index;

@end
12 changes: 9 additions & 3 deletions Classes/PFTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ - (instancetype)initWithFrame:(CGRect)frame items:(NSArray *)items configuration
return self;
}

#pragma mark - Setters
- (void)selectIndex:(NSUInteger)index
{
self.selectedIndexPath = index;
self.selectRowAtIndexPathHandler(index);
[self reloadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
Expand Down Expand Up @@ -73,9 +81,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedIndexPath = indexPath.row;
self.selectRowAtIndexPathHandler(indexPath.row);
[self reloadData];
[self selectIndex:indexPath.row];
PFTableViewCell *cell = (PFTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = self.configuration.cellSelectionColor;
}
Expand Down