Iphone sectionName TableView-我做错了什么?
我在更改TableView上的颜色和字体时遇到了一些问题,我已将其分为4个部分,其中包括名称等,我可以;我不知道我做错了什么Iphone sectionName TableView-我做错了什么?,iphone,xcode,uitableview,ios5,grouped-table,Iphone,Xcode,Uitableview,Ios5,Grouped Table,我在更改TableView上的颜色和字体时遇到了一些问题,我已将其分为4个部分,其中包括名称等,我可以;我不知道我做错了什么 - (NSString *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSString *sectionName = nil; switch(section) { case 0: sectionName = [NSStri
- (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;
}
}
代码向您展示了如何实现TableViewCOntroller的ViewForHeaderInterface委托方法,您需要实现该方法来完成所需的任务。您的代码返回NSString,它应该返回UIView
}
代码向您展示了如何实现TableViewCOntroller的ViewForHeaderInterface委托方法,您需要实现该方法来完成所需的任务。您的代码返回NSString,它应该返回UIView。您应该返回视图而不是字符串 这就是你要回来的
return sectionName;
这是你应该归还的
return sectionHeader;
您应该返回视图而不是字符串 这就是你要回来的
return sectionName;
这是你应该归还的
return sectionHeader;
是在UITableView的标题中显示视图的正确方法。在这里,您可以返回UILabel对象
您正在尝试返回NSString对象,而不是UILabel。方法的返回类型也是错误的。它应该是UIView类型
是在UITableView的标题中显示视图的正确方法。在这里,您可以返回UILabel对象
您正在尝试返回NSString对象,而不是UILabel。方法的返回类型也是错误的。它应该是UIView类型
请解释为什么此代码与问题中的代码不同/更好。一个完全由代码组成的答案通常不是一个好答案。是的,你能解释一下代码吗?我已经试过了,现在它去掉了视图中的部分名称!Thanks@NathanCleary请在方法-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)部分中设置高度请解释为什么此代码与问题中的代码不同/更好。一个完全由代码组成的答案通常不是一个好答案。是的,你能解释一下代码吗?我已经试过了,现在它去掉了视图中的部分名称!Thanks@NathanCleary请在方法-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)节中设置高度