为什么我的UItableView中的按钮没有响应?

戈比纳斯·埃德

我有一个包含多个部分的UItableView,在每个部分中,都有一个包含按钮的View,在每个部分中都定位了一行,但是我已经将该行隐藏了。

简而言之,我的表视图是一个部分的集合,每个部分依次包含按钮,当我单击该按钮时,它没有响应,但是一旦我滚动,我的表从下到上就会响应。这是什么问题?

谢谢!

这是代码:

  - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  {
    sheettable.scrollsToTop=YES;
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)];
    CGRect rect= CGRectMake(0, 0, 320,40);
    UIBezierPath *maskPath;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(UIRectCornerAllCorners) cornerRadii:CGSizeMake(5.0, 5.0)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame =rect;
    maskLayer.path = maskPath.CGPath;
    headerView.layer.mask = maskLayer;
    headerView.backgroundColor=[UIColor greenColor];
    UITextField *label1 = [[UITextField alloc] init] ;
    label1.delegate=self;
    label1.frame = CGRectMake(5, 1, 200, 35);

    label1.font = [UIFont boldSystemFontOfSize:16];
    label1.text = [[result2 objectAtIndex:section] objectForKey:@"cat_desc"];
    UIButton *btn=[[UIButton alloc]init];
    btn.frame=CGRectMake(5, 1, 200, 35);
    btn.tag=section;
    btn.backgroundColor=[UIColor clearColor];
    [headerView addSubview:label1];
    [btn addTarget:self action:@selector(selectedsections) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:btn];
    cameracategory=section;
    return headerView;

 }

 -(void)selectedsections
  {

    if(cameracategory==0)
    {
        NSLog(@"At Index");
    }
    if(cameracategory==1)
    {
        NSLog(@"At Index");
    }
    if(cameracategory==2)
    {
        NSLog(@"At Index");
    }
    if(cameracategory==3)
    {
        NSLog(@"At Index");
    }
    if(cameracategory==4)
    {
        NSLog(@"At Index");
    }

 }
乔治·彼得罗夫(George Petrov)

我测试了您的代码,它可以工作,但是我创建了UITableView我自己。您应该检查一下。也尝试编写更具可读性的代码:),将来会更容易:)

您有一些未对齐的框架(子视图大于父视图)。

- (void)sectionButtonAction:(UIButton *)sender {
    NSLog(@"Section button tapped: %i", sender.tag);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CGRect tableRect = tableView.frame;

    CGRect headerRect = CGRectZero;
    headerRect.size.width = tableRect.size.width;
    headerRect.size.height = 22;

    CGRect bezierRect = CGRectZero;
    bezierRect.size.width = tableRect.size.width;
    bezierRect.size.height = 44;

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    [maskLayer setFrame:bezierRect];
    [maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bezierRect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(5, 5)].CGPath];

    UIView *headerView = [[UIView alloc] initWithFrame:headerRect];
    [headerView setBackgroundColor:[UIColor greenColor]];
    [[headerView layer] setMask:maskLayer];

    CGRect labelRect = CGRectZero;
    labelRect.origin.x = 5;
    labelRect.origin.y = 1;
    labelRect.size.width = 200;
    labelRect.size.height = 35;

    UILabel *headerLabel = [[UILabel alloc] initWithFrame:labelRect];
    [headerLabel setFont:[UIFont boldSystemFontOfSize:16]];
    [headerLabel setText:@"asd"];
    [headerView addSubview:headerLabel];

    CGRect buttonRect = labelRect;

    UIButton *headerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [headerButton setFrame:buttonRect];
    [headerButton setTag:section];
    [headerButton addTarget:self action:@selector(sectionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:headerButton];

    return headerView;
}

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我怎么知道为什么cURL挂起并且没有响应?

为什么我的intlist值没有增加,或者为什么ellipse()函数没有响应?

为什么我的广播接收器没有响应任何电话状态?

为什么在Spring WebMvcTest中没有响应主体

Bootstrap-为什么我的按钮没有响应?

为什么我的OnClicked函数没有响应?

为什么我的Python Turtle屏幕没有响应

为什么程序运行时我的舞台没有响应?(Java FX)

屏幕尺寸减小时,为什么我的图像没有响应?

为什么我会收到〜在stdout上没有响应〜在黑客排名nodejs中

为什么我的bootstrap(3)网格没有响应?

为什么我的表在单击行时没有响应

为什么我的卡在使用引导程序时没有响应?

当我尝试删除文件时,为什么Plupload容器没有响应?

按钮没有响应

为什么我的网页仅在响应式设计视图中具有响应性,而在浏览器中却没有响应性?

为什么我的虚拟机上的虚拟主机没有响应?

为什么我的媒体查询没有响应?

我的按钮在 android studio 中没有响应

为什么我的 RecyclerView 没有响应我的自定义 Click-Event?

为什么我的应用在实现导航图时在 mainActivity 中添加片段后似乎没有响应?

为什么单击“开始”按钮后主循环(此代码中的“运行”)没有响应?

按钮没有响应

为什么我的选择器在 SwiftUI 中没有响应?

为什么我的乌龟键绑定没有响应?

UISearchBar 在 UITableView 中没有响应 JSON 数据

为什么我网站的 CSS 代码在 Bootstrap Studio 中没有响应?

为什么端点没有响应?

为什么我的沙盒 Racket GUI 应用程序没有响应事件?