iOS:如何在viewForHeaderInSection中将滑动删除按钮添加到自定义视图

iOS的菜鸟

有一个类似于表格视图的展开折叠,带有使用的自定义标头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中:

   - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
   {

      .... 
      // Your code here
      ....

      mView.tag = section;
      UISwipeGestureRecognizer* sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(headerViewSwiped:)];
      [sgr setDirection:UISwipeGestureRecognizerDirectionRight]; // change direction accordingly
      [mView addGestureRecognizer:sgr];

      return mView;
   }

   - (void)headerViewSwiped:(UIGestureRecognizer *)gestureRecognizer {
       if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
           UIView *mView= (UIView *)gestureRecognizer.view;

           // use mView.tag property to get the section index which you require to delete from array

           // update your sectionDataSource array remove all the objects from section array
           // so that it will reflect to numberOfSection method

           // then remove all the rows which that section containing from your rowDataSource array
           // so that it will reflect to numberOfRowsInSection method

           // now call [tableView reloadData] method
       }
   }

这是实现您所需的基本思想,并根据您的项目要求更改此代码。

希望这可以帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

iOS:如何在viewForHeaderInSection中将滑动删除按钮添加到自定义视图

来自分类Dev

如何在Android Studio中将ImageView添加到自定义视图类中?

来自分类Dev

当用户在iOS中滑动时,如何在表格视图单元格中添加自定义按钮?

来自分类Dev

如何在iOS 8中将自定义页脚(带有渐变)添加到UIView

来自分类Dev

如何在Sylius中将图像添加到自定义实体?

来自分类Dev

如何在JS Fiddle中将自定义属性添加到head标签?

来自分类常见问题

如何在React Native中将屏幕添加到自定义底部导航

来自分类Dev

如何在自定义插件中将buildscript依赖项添加到项目依赖项?

来自分类Dev

如何在Olingo中将自定义属性添加到元模型?

来自分类Dev

如何在NetSuite中将自定义字段添加到发票

来自分类Dev

如何在Scala中将Builder方法添加到自定义IndexedSeq?

来自分类Dev

如何在Python 3.5中将自定义代码添加到HTTPStatus?

来自分类Dev

如何在Wordpress中将图像添加到自定义主题本身?

来自分类Dev

如何在React Native中将屏幕添加到自定义底部导航

来自分类Dev

如何在Sylius中将图像添加到自定义实体?

来自分类Dev

如何在NetSuite中将自定义字段添加到发票

来自分类Dev

如何在Woocommerce中将自定义字段添加到类别中?

来自分类Dev

如何在Java中将自定义颜色添加到数组中?

来自分类Dev

如何在swift2中将分钟添加到自定义时间

来自分类Dev

如何将按钮图标添加到自定义键盘iOS 8?

来自分类Dev

如何动态地在滚动视图中将自定义布局添加到线性布局

来自分类Dev

在Android中将标签和图像动态添加到自定义视图

来自分类Dev

将自定义视图添加到警报视图

来自分类Dev

将自定义视图添加到警报视图

来自分类Dev

在WordPress中将自定义按钮添加到TinyMCE

来自分类Dev

在C#.net中将自定义按钮添加到gridview

来自分类Dev

在tkinter中将文本添加到自定义圆形按钮

来自分类Dev

无法在Magento中将自定义按钮添加到adminhtml

来自分类Dev

在C#.net中将自定义按钮添加到gridview

Related 相关文章

  1. 1

    iOS:如何在viewForHeaderInSection中将滑动删除按钮添加到自定义视图

  2. 2

    如何在Android Studio中将ImageView添加到自定义视图类中?

  3. 3

    当用户在iOS中滑动时,如何在表格视图单元格中添加自定义按钮?

  4. 4

    如何在iOS 8中将自定义页脚(带有渐变)添加到UIView

  5. 5

    如何在Sylius中将图像添加到自定义实体?

  6. 6

    如何在JS Fiddle中将自定义属性添加到head标签?

  7. 7

    如何在React Native中将屏幕添加到自定义底部导航

  8. 8

    如何在自定义插件中将buildscript依赖项添加到项目依赖项?

  9. 9

    如何在Olingo中将自定义属性添加到元模型?

  10. 10

    如何在NetSuite中将自定义字段添加到发票

  11. 11

    如何在Scala中将Builder方法添加到自定义IndexedSeq?

  12. 12

    如何在Python 3.5中将自定义代码添加到HTTPStatus?

  13. 13

    如何在Wordpress中将图像添加到自定义主题本身?

  14. 14

    如何在React Native中将屏幕添加到自定义底部导航

  15. 15

    如何在Sylius中将图像添加到自定义实体?

  16. 16

    如何在NetSuite中将自定义字段添加到发票

  17. 17

    如何在Woocommerce中将自定义字段添加到类别中?

  18. 18

    如何在Java中将自定义颜色添加到数组中?

  19. 19

    如何在swift2中将分钟添加到自定义时间

  20. 20

    如何将按钮图标添加到自定义键盘iOS 8?

  21. 21

    如何动态地在滚动视图中将自定义布局添加到线性布局

  22. 22

    在Android中将标签和图像动态添加到自定义视图

  23. 23

    将自定义视图添加到警报视图

  24. 24

    将自定义视图添加到警报视图

  25. 25

    在WordPress中将自定义按钮添加到TinyMCE

  26. 26

    在C#.net中将自定义按钮添加到gridview

  27. 27

    在tkinter中将文本添加到自定义圆形按钮

  28. 28

    无法在Magento中将自定义按钮添加到adminhtml

  29. 29

    在C#.net中将自定义按钮添加到gridview

热门标签

归档