Ios 在节中的集合标题下添加视图
我想在Ios 在节中的集合标题下添加视图,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,我想在UITableView中的节标题下添加一个视图。可能吗?这是我到目前为止的代码,用该代码替换了该部分: -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 4) { return 10; } else { return 20; } } -(UIView *)tabl
UITableView
中的节标题下添加一个视图。可能吗?这是我到目前为止的代码,用该代码替换了该部分:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 4) {
return 10;
} else
{
return 20;
}
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 4) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor blackColor];
return view;
} else {
return nil;
}
}
从概念上讲,我不认为这是在标题下添加另一个视图。相反,请考虑将页眉的高度设为您希望页眉的高度等于黑线的高度。然后,您所要做的就是创建一个附加视图(黑线),并将其添加为标题的子视图,例如
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor whiteColor];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, view.frame.size.height - 2.0, view.frame.size.width, 2.0)];
[lineView setBackgroundColor:[UIColor blackColor]];
[view addSubview:lineView];
从概念上讲,我不认为这是在标题下添加另一个视图。相反,请考虑将页眉的高度设为您希望页眉的高度等于黑线的高度。然后,您所要做的就是创建一个附加视图(黑线),并将其添加为标题的子视图,例如
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 10)];
view.backgroundColor = [UIColor whiteColor];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, view.frame.size.height - 2.0, view.frame.size.width, 2.0)];
[lineView setBackgroundColor:[UIColor blackColor]];
[view addSubview:lineView];
@EvgeniyS你误解我了:我想先显示正常的标题,然后显示视图(只是一条黑线),然后显示行,然后再显示视图的正常标题sections@0x7fffffff我怎么能做到呢,如果想在节的标题下显示视图?@EvgeniyS你误解了我:我想显示正常的标题,然后是视图(只是一条黑线),然后是行,然后是节的正常标题sections@0x7fffffff如果要在节的标题下显示视图,该如何操作?