2011-09-05 64 views
1

我添加兩個按鈕,我的UITableView節頭。按鈕操作方法需要知道段號,但它收到的唯一參數是按鈕本身。可以從按鈕的某個超級視圖中獲得分區號?如何從UITable SectionHeaderView中獲取節號?

我知道我可以(可能通過使用標籤字段)以某種方式嵌入在按鈕的部分號碼,我寧願如果可以不這樣做的。

此代碼讓小區內的按鈕的索引路徑的工作:

NSIndexPath *indexPath = [self.tableView indexPathForCell: (UITableViewCell *)sender.superview.superview] 

我正在尋找的東西相當於用於獲取從按鈕在節頭的部分號碼。

回答

0

雖然分配的按鈕爲每個部分,設置標籤像

button.tag = 0 // For section 1; 
button.tag = 1 // For section 2; 

// and so on; 

這種方式調用您的按鈕操作時,您可以檢查使用

if (button.tag == 0) 
    // write the code for section 1; 
+0

謝謝,這就是我最終做的。 – Alec

0

我已經做了這樣的事情使用標籤字段。這可能不是絕對最好的方式,但它確實有效。

+0

我覺得你的標籤對,我找不到更好的方法。 – Alec