【发布时间】:2015-02-20 06:42:24
【问题描述】:
有一个使用viewForHeaderInSection 自定义标题的类似展开折叠的表格视图。
在那,我想添加滑动手势功能来删除相同的视图,即section header。
我的viewForHeaderInSection 代码是,
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
mView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 110)]autorelease];
mView.backgroundColor=[UIColor whiteColor];
[mView setBackgroundColor:[UIColor whiteColor]];
UILabel *title=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 28)];
title.text=[[updateDataArray objectAtIndex:section] objectForKey:@"message"];
title.font = [UIFont fontWithName:@"Raleway-Medium" size:18];
UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
[bt setFrame:CGRectMake(0, 0, 320, 44)];
[bt setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[bt setTag:section];
addCellFlag=2;
[bt.titleLabel setFont:[UIFont systemFontOfSize:20]];
[bt.titleLabel setTextAlignment:NSTextAlignmentCenter];
[bt.titleLabel setTextColor:[UIColor blueColor]];
[bt setBackgroundColor:[UIColor whiteColor]];
[bt addTarget:self action:@selector(addCell:) forControlEvents:UIControlEventTouchUpInside];
[mView addSubview:bt];
if (section<updateDataArray.count-1) {
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 2, 320, 0)];
lineView.backgroundColor=[UIColor lightGrayColor];
[bt addSubview:lineView];
[lineView release];
}
mView.backgroundColor=[UIColor clearColor];
[mView addSubview:title];
return mView;
}
请建议如何创建滑动以删除表格视图行等按钮功能?我也想要节标题中的那个按钮。
【问题讨论】:
-
您没有从 viewForHeaderInSection 方法返回任何视图?
-
另外,一旦标题被删除,你是否也需要删除整个部分(其中的所有行)?
-
滑动手势都不起作用,因为它是自定义视图,所以我可以对其应用任何表格视图委托方法。
标签: ios uitableview view uiswipegesturerecognizer