简体   繁体   中英

How can i put the image in the section of table in the titleForHeaderInSection method?

i have so confused to make an image in the table's header section , and i have make put the image in the cell of table but i cannot understand how to make put image in the section part of table . here is my code of that method ..

  • (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if (section == 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"; with String 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;

}

}

You're using the wrong Delegate method. That delegate method, from the UITableViewDataSource only allows you to provide a new text string for the default section header types.

To add an image to the section headers you want to take a look at the UITableViewDelete methods

Modifying the Header and Footer of Sections
– tableView:viewForHeaderInSection:
– tableView:viewForFooterInSection:
– tableView:heightForHeaderInSection:
– tableView:heightForFooterInSection:

Using these you can provide a new view (rather than just the text) for a header of a section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM