2015-06-14 32 views
1

我有一個表,有兩個部分。我可以在索引處選擇行 - 但我無法區分這些部分。不同部分的索引selectrow

該表是一個拉出式菜單 - 僅在代碼中創建。

所選項目的委託方法是

func sideBarControlDidSelectRow(indexPath: NSIndexPath) { 
    delegate?.sideBarDidSelectButtonAtIndex(indexPath.row) 
    sectionis = indexPath.section 
    NSLog("Index Path Section %d", indexPath.section) 
} 

這給了我在控制檯部分。

但視圖控制器上的所有我是

func sideBarDidSelectButtonAtIndex(index: Int){ 
    switch(index) { 
     etc. 
    } 
} 

我需要什麼,能夠做的是一樣的東西

func sideBarDidSelectButtonAtIndex(index: Int){ 
    if section == 0 { 
     switch(index){ 
      etc. 
     } 
    } 
} 

但如果我嘗試再二元運算符不能應用於類型部分的操作數

這已經是明顯的事情了,因爲表格總是有段 - 但答案讓我無法迴避。

回答

1

在委託協議只需更新方法sideBarDidSelectButtonAtIndex的接受申報NSIndexPath價值的變動:

func sideBarDidSelectButtonAtIndex(index: Int) 

func sideBarDidSelectButtonAtIndex(indexPath: NSIndexPath) 

那麼你可以刪除這個方法

func sideBarControlDidSelectRow(indexPath: NSIndexPath) { 
    delegate?.sideBarDidSelectButtonAtIndex(indexPath.row) 
} 

和用

替換它的呼叫
delegate?.sideBarDidSelectButtonAtIndex(indexPath) 

然後你會得到充分的indexPath,可能你想

+0

那麼容易什麼,當你知道怎麼辦。 – techguy