2012-09-30 24 views
0

我有以下代碼將一個按鈕添加到我的自定義標題的部分。爲什麼我的UIButton沒有添加到我的viewForSectionHeader的自定義標題視圖

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section { 
    if (tableView == menuListTableView) { 
     UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)] autorelease]; 

    UIButton *headerButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [headerButton setFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)]; 
    [headerButton setImage:[UIImage imageNamed:@"Gray_Gradient.png"] forState:UIControlStateSelected]; 
    [headerButton addTarget:nil action:@selector(toggleOpen:) forControlEvents:UIControlEventTouchUpInside]; 
    [headerView addSubview:headerButton]; 

    return headerView; 
} 
return nil; 
} 

爲什麼我的按鈕沒有添加到自定義標題視圖?在調試模式下檢查時,headerview的子視圖數組似乎爲零。

+1

我想你想返回'headerView'而不是'headerButton'? – barley

+0

是它的標題視圖..因爲我正在嘗試過於ma things的事情..我忘了編輯這一個.. –

回答

0

哦,我自己得到了答案!我看着按鈕代碼..和控制狀態設置爲UIControlStateSelected。而不是UIControlStateNormal。它如此無知我。對不起,煩請傢伙!

+1

您還添加了一個零目標:) –

+0

其實匆忙完成這個項目..我犯了幾個愚蠢的錯誤..我真的需要集中..謝謝卡爾的答覆.. –

0

您是否看到標題視圖本身?檢查標題視圖的高度。還要檢查圖像是否存在。如果有疑問,請將按鈕類型更改爲圓角矩形,並查看它是否正確添加。

+0

感謝您的答案..是的,我也試過這樣做..但它沒有顯示在陣列..甚至現在它似乎沒有填充該數組..但現在至少顯示在標題部分.. –

相關問題