Inherits from NSObject
Declared in VPPDropDown.h
VPPDropDown.m

Overview

VPPDropDown is a library that allows you to create dropdown-like menus in a table view, as seen in old Twitter 3 for iPhone.

You can create three kinds of dropdown menus (VPPDropDownType):

  • VPPDropDownTypeDisclosure, childs of drop down cell are treated as disclosure cells, useful for grouping detailed view controllers.
  • VPPDropDownTypeSelection, childs of drop down cell are treated as selection cells, useful for editing preferences.
  • VPPDropDownTypeCustom, childs of drop down cell should be decorated by the delegate.

You can mix different dropdowns in the same or different section.

Take into account that if you add multiple dropdowns in the same section, they must be together, so all cells between the first dropdown and the last one are managed by the library.

Relative index path

If you are using any of the relative index path deprecated methods, you should read this. Otherwise, skip it.

The concepts of relative index path and global index path are widely used in this library. Some method signatures require a relative index path, and some requires both index paths.

What is exactly a relative index path? If in the table’s section where the drop down will be placed are more drop downs, the relative index path’s row is substraction of the number of rows in the precedent drop downs (using numberOfRows dropdown property) to the tableview indexpath’s row.

This relative index path is used to know which dropdown’s child cell is been treated.

The global index path is the tableview’s index path itself.

Checking the included sample application will clear these concepts.

If there is only one dropdown per section, relativeIndexPath and globalIndexPath have the same value.

Tasks

Reading dropdown setup

Managing dropdown status

Storing data

  •   object

    This property stores custom data. Use it to store any information you want.

    property

Constructors

Table view data source

Table view delegate

Properties

delegate

Holds a reference to the delegate

@property (nonatomic, readonly) id<VPPDropDownDelegate> delegate

Declared In

VPPDropDown.h

elements

VPPDropDownElement objects. They conform the dropdown’s childs.

@property (nonatomic, readonly) NSArray *elements

Declared In

VPPDropDown.h

expanded

Specifies whether the dropdown is exanded or not.

@property (nonatomic, assign, getter=isExpanded) BOOL expanded

Declared In

VPPDropDown.h

indexPath

The root cell’s indexPath. All childs will be placed after it.

@property (nonatomic, readonly) NSIndexPath *indexPath

Declared In

VPPDropDown.h

numberOfRows

Indicates the dropdown’s visible number of rows.

@property (nonatomic, readonly) int numberOfRows

Discussion

If the dropdown is contracted, numberOfRows will be 0. Otherwise, numberOfRows will be the count of elements.

Declared In

VPPDropDown.h

object

This property stores custom data. Use it to store any information you want.

@property (nonatomic, retain) id object

Declared In

VPPDropDown.h

selectedIndex

Specifies the dropdown’s selected index.

@property (nonatomic, assign) int selectedIndex

Discussion

This property only applies to selection dropdowns. If you change this value manually, no dropdown delegate’s method will be called.

Declared In

VPPDropDown.h

tableView

The tableView where the dropdown is.

@property (nonatomic, readonly) UITableView *tableView

Declared In

VPPDropDown.h

title

The root cell’s title.

@property (nonatomic, readonly) NSString *title

Declared In

VPPDropDown.h

type

Indicates the drop down type.

@property (nonatomic, readonly) VPPDropDownType type

Discussion

Type can be:

  • VPPDropDownTypeDisclosure, childs of drop down cell are treated as disclosure cells, useful for grouping detailed view controllers.
  • VPPDropDownTypeSelection, childs of drop down cell are treated as selection cells, useful for editing preferences.
  • VPPDropDownTypeCustom, childs of drop down cell should be decorated by the delegate.

Declared In

VPPDropDown.h

usesEntireSection

Tells the dropdown if it is using the entire tableView’s section.

@property (nonatomic, assign) BOOL usesEntireSection

Discussion

This changes the expanding/contracting animation.

  • If usesEntireSection is set to YES, expanding/contracting will be done by inserting/removing cells.
  • Otherwise, expanding/contracting will be done refreshing the section.

Declared In

VPPDropDown.h

Class Methods

tableView:cellForRowAtIndexPath:

Returns the corresponding cell for the given parameters.

+ (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Discussion

LIbrary will automatically set up the cell according to the corresponding dropdown.

Declared In

VPPDropDown.h

tableView:didSelectRowAtIndexPath:

Indicates that the specified indexPath has been selected.

+ (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Discussion

Library will automatically notify the dropdown containing the selected row.

Declared In

VPPDropDown.h

tableView:dropdownsContainIndexPath:

Indicates if the given indexPath is contained in any dropdown associated with the given tableView.

+ (BOOL)tableView:(UITableView *)tableView dropdownsContainIndexPath:(NSIndexPath *)indexPath

Declared In

VPPDropDown.h

tableView:heightForRowAtIndexPath:

Lets specify a custom height for the given index path.

+ (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

Discussion

This method will automatically delegate on the corresponding dropdown’s delegate. If it does not implement the method dropDown:heightForElement:atIndexPath:, tableView.rowHeight will be returned, so you should call this only when the dropdown’s delegate is expected to return an height.

Declared In

VPPDropDown.h

tableView:isRootCellAtIndexPath:

Returns YES if the given indexPath is root for any dropdown. Otherwise returns NO.

+ (BOOL)tableView:(UITableView *)tableView isRootCellAtIndexPath:(NSIndexPath *)indexPath

Declared In

VPPDropDown.h

tableView:numberOfExpandedRowsInSection:

Returns the current number of expanded cells for all dropdowns included in the given section of the given table.

+ (NSInteger)tableView:(UITableView *)tableView numberOfExpandedRowsInSection:(NSInteger)section

Discussion

Important the returned number doesn’t take into account any root cell.

Example for a dropdown with three child rows, if the dropdown is expanded the returned value will be three. Otherwise it will be zero.

Declared In

VPPDropDown.h

Instance Methods

cellForRowAtRelativeIndexPath:globalIndexPath:

Deprecated Returns the corresponding cell for the given parameters.

- (UITableViewCell *)cellForRowAtRelativeIndexPath:(NSIndexPath *)relativeIndexPath globalIndexPath:(NSIndexPath *)globalIndexPath

Discussion

Deprecated Use tableView:cellForRowAtIndexPath: instead.

Declared In

VPPDropDown.h

containsRelativeIndexPath:

Deprecated Indicates if the given relativeIndexPath is contained and managed by the dropdown.

- (BOOL)containsRelativeIndexPath:(NSIndexPath *)relativeIndexPath

Discussion

Deprecated Use tableView:dropdownsContainIndexPath: instead.

Declared In

VPPDropDown.h

didSelectRowAtRelativeIndexPath:globalIndexPath:

Deprecated Indicates the dropdown the corresponding cell for the given parameters has been selected.

- (void)didSelectRowAtRelativeIndexPath:(NSIndexPath *)relativeIndexPath globalIndexPath:(NSIndexPath *)globalIndexPath

Declared In

VPPDropDown.h

initDisclosureWithTitle:tableView:indexPath:delegate:elementTitles:

Returns a newly initialized disclosure dropdown.

- (VPPDropDown *)initDisclosureWithTitle:(NSString *)title tableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath delegate:(id<VPPDropDownDelegate>)delegate elementTitles:(NSString *)firstObject, ...

Parameters

title

Indicates the title of the root cell.

tableView

The tableView where the dropdown will be placed.

indexPath

The tableView’s indexPath where the dropdown will be placed.

delegate

A reference to the delegate.

firstObject,

… A comma-separated list of strings ending with nil. It represents the titles of all dropdown’s childs.

Declared In

VPPDropDown.h

initSelectionWithTitle:tableView:indexPath:delegate:selectedIndex:elementTitles:

Returns a newly initialized selection dropdown.

- (VPPDropDown *)initSelectionWithTitle:(NSString *)title tableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath delegate:(id<VPPDropDownDelegate>)delegate selectedIndex:(int)selectedIndex elementTitles:(NSString *)firstObject, ...

Parameters

title

Indicates the title of the root cell.

tableView

The tableView where the dropdown will be placed.

indexPath

The tableView’s indexPath where the dropdown will be placed.

delegate

A reference to the delegate.

selectedIndex

The initial selected index.

firstObject,

… A comma-separated list of strings ending with nil. It represents the titles of all dropdown’s childs.

Declared In

VPPDropDown.h

initWithTitle:type:tableView:indexPath:elements:delegate:

Returns a newly initialized dropdown.

- (VPPDropDown *)initWithTitle:(NSString *)title type:(VPPDropDownType)type tableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath elements:(NSArray *)elements delegate:(id<VPPDropDownDelegate>)delegate

Parameters

title

Indicates the title of the root cell.

type

Should be one of:

  • VPPDropDownTypeDisclosure, childs of drop down cell are treated as disclosure cells, useful for grouping detailed view controllers.
  • VPPDropDownTypeSelection, childs of drop down cell are treated as selection cells, useful for editing preferences.
  • VPPDropDownTypeCustom, childs of drop down cell should be decorated by the delegate.
tableView

The tableView where the dropdown will be placed.

indexPath

The tableView’s indexPath where the dropdown will be placed.

elements

An array of VPPDropDownElement objects. They will conform the dropdown’s childs.

delegate

A reference to the delegate.

Discussion

This is the designated initializer.

Declared In

VPPDropDown.h

isRootCellAtIndexPath:

Indicates if dropdown’s root cell is placed in the given indexPath.

- (BOOL)isRootCellAtIndexPath:(NSIndexPath *)indexPath

Declared In

VPPDropDown.h

isRootCellAtRelativeIndexPath:

Deprecated Indicates if dropdown’s root cell is placed in the given relativeIndexPath.

- (BOOL)isRootCellAtRelativeIndexPath:(NSIndexPath *)relativeIndexPath

Discussion

Deprecated Use isRootCellAtIndexPath: instead.

Declared In

VPPDropDown.h