Hello, this is my first question, so if I didn't do the tags correctly, I'm sorry. I tried... Well here is my question: I am hoping someone can tell me how to do a 2-line section header for a plain tableview. The problems I am having are: 1) I cannot find an image that will mimic that of the default 1-line section header. Can someone share one with me, or tell me how I can find one? 2) I cannot seem to get the section header text on two lines, since I am pulling it from the fetched results controller, a "field" (sorry if wrong terminology) that I custom defined on the class for my table. So this "field" has multiple field values in it, and I have no way to take them apart... Any help would be appreciated.
A:
Use these methods (this code sample should work):
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 280, 40)];
label.numberOfLines = 2;
label.text = @"line 1\nline 2\n";
return [label autorelease];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44.0;
}
The method - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
will work for a single line of text only. Note that the frame generated has 0,0 origin, and a height specified; the origin will be adjusted to place the header correctly, and the height is set by the following method.
Paul Lynch
2010-03-30 22:18:56