2010-08-05 18 views
0

我很困惑,在桌子的標題部分製作圖像, ,我已經把圖像放在桌子的單元格中,但是我無法理解如何在桌子的部分部分中放置圖像。 這是我的該方法的代碼..如何將圖像放在titleForHeaderInSection方法的表格部分中?

  • (的NSString *)的tableView:(UITableView的*)的tableView titleForHeaderInSection:(NSInteger的)部分{

    如果(部分== 0){

// return @「Alpahbets」; With String

UILabel *alphabet = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)]; 
    alphabet.text = @"Alphabet"; 
    return alphabet.text; 





} if (section == 1) { 

// return @「Roman」;與字符串 UILabel * roman = [[UILabel alloc] initWithFrame:CGRectMake(50,100,200,100)]; roman.text = @「Roman」; return roman.text;

} else { 

// return @"Digits"; With String 
    UILabel *digit = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 200, 100)]; 
    digit.text = @"Digit"; 
    return digit.text; 

} 

}

回答

4

你使用了錯誤的委託方法。來自UITableViewDataSource的代理方法僅允許您爲默認節標題類型提供新的文本字符串。

將圖像添加到要看看在UITableViewDelete方法

修改第
的頁眉和頁腳節頭 - 的tableView:viewForHeaderInSection:
- 的tableView:viewForFooterInSection:
- tableView:heightForHeaderInSection:
- tableView:heightForFooterInSection:

使用這些,你可以provi爲一個部分的標題創建一個新的視圖(而不僅僅是文本)。

相關問題