我在改變TableView上的顏色和字體時遇到了一些麻煩,我已經將它們分成了4個部分,名稱等,我似乎可以使它工作我不知道我在做什麼錯了?sectionName TableView - 我做錯了什麼?
- (NSString *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionName = nil;
switch(section)
{
case 0:
sectionName = [NSString stringWithString:@"Date"];
break;
case 1:
sectionName = [NSString stringWithString:@"Gig"];
break;
case 2:
sectionName = [NSString stringWithString:@"City"];
break;
case 3:
sectionName = [NSString stringWithString:@"Country"];
break;
}
UILabel *sectionHeader = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)] autorelease];
sectionHeader.backgroundColor = [UIColor clearColor];
sectionHeader.font = [UIFont boldSystemFontOfSize:18];
sectionHeader.textColor = [UIColor whiteColor];
sectionHeader.text = sectionName;
return sectionName;
}
請解釋爲什麼此代碼與問題中的代碼不同/更好。僅由代碼組成的答案通常不是一個好答案。 – jrturton
是的,你可以解釋一下代碼嗎?我已經試過了,現在需要關閉部分名稱!謝謝 –
@NathanCleary請在方法中設置高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection :(NSInteger)部分 – Neo