     func tableView(tableView: UITableView, numberOfSubRowsAtIndexPath indexPath: NSIndexPath) -> Int
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
     func tableView(tableView: UITableView, cellForSubRowAtIndexPath indexPath: FlexibleIndexPath) -> UITableViewCell
-    
     optional func numberOfSectionsInTableView(tableView: UITableView) -> Int
     optional func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
     optional func tableView(tableView: UITableView, heightForSubRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
     optional func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
-    optional func tableView(tableView: UITableView, didSelectSubRowAtIndexPath indexPath: NSIndexPath)
+    optional func tableView(tableView: FlexibleTableView, didSelectSubRowAtIndexPath indexPath: FlexibleIndexPath)
     optional func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
     optional func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
     optional func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?

    optional func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
    optional func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
    optional func tableView(tableView: UITableView, shouldExpandSubRowsOfCellAtIndexPath indexPath: NSIndexPath) -> Bool
    
    optional func scrollViewDidScroll(scrollView: UIScrollView)
    optional func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool)
}

public class FlexibleIndexPath: NSObject{

        tableView.deselectRowAtIndexPath(indexPath, animated:true)
        
        let cell = tableView.cellForRowAtIndexPath(indexPath)
        
        if let x = cell as? FlexibleTableViewCell {
            
            if !x.expandable { return }
            
            x.expanded = !x.expanded
            
            var _indexPath = indexPath
            let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(_indexPath)
            if (x.expanded && shouldExpandOnlyOneCell) {
                _indexPath = correspondingIndexPath.ns;
                collapseCurrentlyExpandedIndexPaths()
            }
            
            let numberOfSubRows = numberOfSubRowsAtIndexPath(correspondingIndexPath.ns)
            
            var expandedIndexPaths = [NSIndexPath]()
            let row = _indexPath.row;
            let section = _indexPath.section;
            
            for var index = 1; index <= numberOfSubRows; index++ {
                let expIndexPath = NSIndexPath(forRow:row+index, inSection:section)
                expandedIndexPaths.append(expIndexPath)
            }
            
            if (x.expanded)
            {
                setExpanded(true, forCellAtIndexPath:correspondingIndexPath)
                insertRowsAtIndexPaths(expandedIndexPaths, withRowAnimation:UITableViewRowAnimation.Top)
            }
            else
            {
                setExpanded(false, forCellAtIndexPath:correspondingIndexPath)
                deleteRowsAtIndexPaths(expandedIndexPaths, withRowAnimation:UITableViewRowAnimation.Top)
            }
            
            x.accessoryViewAnimation()
            
            flexibleTableViewDelegate.tableView?(self, didSelectRowAtIndexPath:indexPath)
            
        } else {
            let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(indexPath)
            
            flexibleTableViewDelegate.tableView?(self, didSelectSubRowAtIndexPath:correspondingIndexPath)
        }
    }
    
