• <bdo id='eruV6'></bdo><ul id='eruV6'></ul>

    <tfoot id='eruV6'></tfoot>
    <i id='eruV6'><tr id='eruV6'><dt id='eruV6'><q id='eruV6'><span id='eruV6'><b id='eruV6'><form id='eruV6'><ins id='eruV6'></ins><ul id='eruV6'></ul><sub id='eruV6'></sub></form><legend id='eruV6'></legend><bdo id='eruV6'><pre id='eruV6'><center id='eruV6'></center></pre></bdo></b><th id='eruV6'></th></span></q></dt></tr></i><div id='eruV6'><tfoot id='eruV6'></tfoot><dl id='eruV6'><fieldset id='eruV6'></fieldset></dl></div>
    1. <legend id='eruV6'><style id='eruV6'><dir id='eruV6'><q id='eruV6'></q></dir></style></legend>

      <small id='eruV6'></small><noframes id='eruV6'>

    2. 无法在 UITableview 中的单元格内单击 UIButton

      时间:2023-07-08
        • <bdo id='CERE7'></bdo><ul id='CERE7'></ul>
          <tfoot id='CERE7'></tfoot>
        • <legend id='CERE7'><style id='CERE7'><dir id='CERE7'><q id='CERE7'></q></dir></style></legend>
          • <small id='CERE7'></small><noframes id='CERE7'>

            <i id='CERE7'><tr id='CERE7'><dt id='CERE7'><q id='CERE7'><span id='CERE7'><b id='CERE7'><form id='CERE7'><ins id='CERE7'></ins><ul id='CERE7'></ul><sub id='CERE7'></sub></form><legend id='CERE7'></legend><bdo id='CERE7'><pre id='CERE7'><center id='CERE7'></center></pre></bdo></b><th id='CERE7'></th></span></q></dt></tr></i><div id='CERE7'><tfoot id='CERE7'></tfoot><dl id='CERE7'><fieldset id='CERE7'></fieldset></dl></div>

              <tbody id='CERE7'></tbody>
              • 本文介绍了无法在 UITableview 中的单元格内单击 UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                已经搜索了一些可能的修复方法,但都没有解决我的问题.

                searched already some possible fixes but all did not solve mine.

                我一直点击 uitableview 中的单元格而不是其中的按钮.

                i keep clicking the cell in the uitableview rather than the buttons inside it.

                这是我的代码:

                - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath{
                
                    static NSString *CellIdentifier = @"Cell";
                
                    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                    if (cell == nil) {
                        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                    }
                
                    cell.backgroundColor = [UIColor blackColor];
                
                    UIView *v  = nil;
                    NSArray *array = [cell subviews];
                
                    for (v in array) {
                        NSLog(@"%@",[v class]);
                        if( [v isKindOfClass:[UIView class]] ){
                           [v removeFromSuperview];
                        }
                    }
                
                    //tb
                    if (tableView == self.tb) {
                
                        v = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.tb.bounds.size.width, 120.0)];
                
                        if([feeds count]>0){
                            UIImageView *box=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statusBox.png"]];
                
                            box.userInteractionEnabled = YES;
                            [v addSubview:box];
                
                            AsyncImageView *imageView1 = [[AsyncImageView alloc] initWithFrame:CGRectMake(10, 20.0f, 34.0f, 34.0f)];
                            imageView1.contentMode = UIViewContentModeScaleAspectFill;
                            imageView1.clipsToBounds = YES;
                
                            //cancel loading previous image for cell
                            [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView1];
                            if (users1 != nil && users1.imagelink != nil && (id) users1.imagelink !=   [NSNull null]){
                               imageView1.imageURL = [NSURL URLWithString:users1.imagelink];
                            }
                            else{
                                imageView1.image=[UIImage imageNamed:@"default_ProfilePic.png"];
                            }
                
                            UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)];
                            tapped.numberOfTapsRequired = 1;
                            [imageView1 addGestureRecognizer:tapped];
                            [tapped release];
                
                            imageView1.userInteractionEnabled = NO;
                            [v addSubview:imageView1];
                
                
                            UIFont *font     = [UIFont fontWithName:@"TrebuchetMS-Bold" size:11];
                            UILabel *descLabel1 = [[UILabel alloc] initWithFrame: CGRectMake(52, 23, 160, 48)];
                            descLabel1.text                 = [NSString stringWithFormat:@"%@ %@",users1.userfirstn,users1.userlastn];
                            descLabel1.textColor            = [UIColor blackColor];
                            descLabel1.font                 = font;
                            descLabel1.adjustsFontSizeToFitWidth=YES;
                            descLabel1.numberOfLines = 0;
                            CGSize expectedLabelSize = [descLabel1.text sizeWithFont:descLabel1.font
                                                               constrainedToSize:descLabel1.frame.size
                                                                   lineBreakMode:UILineBreakModeWordWrap];
                
                            CGRect newFrame = descLabel1.frame;
                            newFrame.size.height = expectedLabelSize.height;
                            descLabel1.frame = newFrame;
                            descLabel1.numberOfLines = 0;
                
                            descLabel1.userInteractionEnabled = NO;
                            [v addSubview:descLabel1];
                
                
                            UILabel *descLabel2= [[UILabel alloc] initWithFrame: CGRectMake(52, 43, 200, 48)];
                            StatusClass *stat1=[feeds objectAtIndex:indexPath.row];
                            descLabel2.text                 = [stat1 statcreate];
                            descLabel2.textColor            = [UIColor blackColor];
                            descLabel2.font                 = font;
                            descLabel2.adjustsFontSizeToFitWidth=YES;
                            descLabel2.numberOfLines = 0;
                            CGSize expectedLabelSize2 = [descLabel2.text sizeWithFont:descLabel2.font
                                                                constrainedToSize:descLabel2.frame.size
                                                                    lineBreakMode:UILineBreakModeWordWrap];
                
                            CGRect newFrame2 = descLabel2.frame;
                            newFrame2.size.height = expectedLabelSize2.height;
                            descLabel2.frame = newFrame2;
                            descLabel2.numberOfLines = 0;
                
                            descLabel2.userInteractionEnabled = NO;
                            [v addSubview:descLabel2];
                
                            UILabel *descLabel3= [[UILabel alloc] initWithFrame: CGRectMake(10, 63, 280, 80)];
                            StatusClass *stat=[feeds objectAtIndex:indexPath.row];
                            descLabel3.text                 = [stat stattext];
                            descLabel3.textColor            = [UIColor blackColor];
                            descLabel3.font                 = font;
                            descLabel3.adjustsFontSizeToFitWidth=YES;
                            descLabel3.numberOfLines = 0;
                
                            descLabel3.userInteractionEnabled = NO;
                            [v addSubview:descLabel3];
                
                            //comment button
                            UIButton *buttonC = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                            [buttonC addTarget:self action:@selector(sendComment:) forControlEvents:UIControlEventTouchUpInside];
                            [buttonC setImage:[UIImage imageNamed:@"comment.png"] forState:UIControlStateNormal];
                            buttonC.frame = CGRectMake(2, 160, 145, 35);
                
                            buttonC.userInteractionEnabled = YES;
                            [v addSubview:buttonC];
                
                            //share button
                            UIButton *buttonS = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                            buttonS.tag = indexPath.row;
                            [buttonS addTarget:self action:@selector(sendShare:) forControlEvents:UIControlEventTouchUpInside];
                            [buttonS setImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
                            buttonS.frame = CGRectMake(150, 160, 140, 35);
                
                            buttonS.userInteractionEnabled = YES;
                            [v addSubview:buttonS];
                
                        }
                        v.userInteractionEnabled = YES;
                        [cell addSubview:v];
                    }
                    return cell; 
                }
                

                我还尝试了按钮的 UITapGestureRecognizer,但仍然无法正常工作.

                I also tried the UITapGestureRecognizer for the buttons and still not working.

                谢谢.

                推荐答案

                我只是对这个问题感到困惑....

                I'm just baffled by this issue....

                我设法在一个项目上解决了这个问题:

                I managed to fix this problem by doing this on one project:

                func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
                    let cell = tableView.dequeueReusableCellWithIdentifier("RegCell", forIndexPath: indexPath) as! CustomCell
                
                    cell.contentView.userInteractionEnabled = false // <<-- the solution
                
                    return cell
                }
                

                但同样的方法不适用于不同的项目.我不知道为什么...

                but the same did not work for a different project. I have no idea why...

                这篇关于无法在 UITableview 中的单元格内单击 UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何增加 UIButton 的选择区域? 下一篇:如何调整 UIButton 的大小以适应文本而不使其比屏幕更宽?

                相关文章

                <i id='PxPbo'><tr id='PxPbo'><dt id='PxPbo'><q id='PxPbo'><span id='PxPbo'><b id='PxPbo'><form id='PxPbo'><ins id='PxPbo'></ins><ul id='PxPbo'></ul><sub id='PxPbo'></sub></form><legend id='PxPbo'></legend><bdo id='PxPbo'><pre id='PxPbo'><center id='PxPbo'></center></pre></bdo></b><th id='PxPbo'></th></span></q></dt></tr></i><div id='PxPbo'><tfoot id='PxPbo'></tfoot><dl id='PxPbo'><fieldset id='PxPbo'></fieldset></dl></div>

                  <small id='PxPbo'></small><noframes id='PxPbo'>

                  <legend id='PxPbo'><style id='PxPbo'><dir id='PxPbo'><q id='PxPbo'></q></dir></style></legend>
                    <bdo id='PxPbo'></bdo><ul id='PxPbo'></ul>

                    <tfoot id='PxPbo'></tfoot>