[英]tableViewController in iPhone programmatically
我想以编程方式开发TableView
。
我想将节标题添加到tableView
。
它已添加但与tableCell
重叠。
但是,当我通过情节提要开发代码时,它以正确的方式出现。
请建议我如何将tableView
行与tableview
部分分开?
我的代码:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempView= [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[tempView setBackgroundColor:[UIColor clearColor]];
UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,tableView.bounds.size.width,44)];
tempLabel.backgroundColor=[UIColor grayColor];
tempLabel.textColor = [UIColor yellowColor];
tempLabel.shadowColor = [UIColor whiteColor];
tempLabel.textColor = [UIColor redColor];
tempLabel.font = [UIFont fontWithName:@"Helvetica" size:18];
tempLabel.font = [UIFont boldSystemFontOfSize:18];
if (section==0)
tempLabel.text=[NSString stringWithFormat:@"Introduction"];
else if(section==1)
tempLabel.text=[NSString stringWithFormat:@"The Nuron"];
else if(section==2)
tempLabel.text=[NSString stringWithFormat:@"Brain Developoment"];
else if(section==3)
tempLabel.text=[NSString stringWithFormat:@"Sensation &Perception"];
else if(section==4)
tempLabel.text=[NSString stringWithFormat:@"Stress"];
else if(section==5)
tempLabel.text=[NSString stringWithFormat:@"Sleep"];
else if(section==6)
tempLabel.text=[NSString stringWithFormat:@"New Diagonistic Method"];
else if(section==7)
tempLabel.text=[NSString stringWithFormat:@"Potential Therapy"];
[tempView addSubview:tempLabel];
return tempView;
}
如果您未实现tableView:heightForHeaderInSection:
iOS会假定标头的高度为0点。
实现它并返回所需的高度:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40.0f;
}
我认为您已将部分背景颜色设置为清晰的颜色,这就是为什么它会重叠的原因。
[tempView setBackgroundColor:[UIColor whitecolor]];//or any other color
让我检查它是否正常!!!
快乐编码!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.