Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中:无法在UITableview中的子视图内部进行触摸_Ios_Objective C_Iphone_Uitableview - Fatal编程技术网

在iOS中:无法在UITableview中的子视图内部进行触摸

在iOS中:无法在UITableview中的子视图内部进行触摸,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我有一个带有图像按钮的UITableview。当按下按钮时,它将动态添加子视图(表视图),如下图所示。我无法在下拉列表(表视图)中选择第二个选项 问题是下拉列表的高度超出了表格行。因此,我无法选择第二个选项 有人能解决这个问题吗?或者在UITableView中显示下拉列表 编辑: 此选项在UITextField下拉列表中正常工作。但在UITableView中不工作 下拉代码: - (id)showDropDown:(UIButton *)b:(CGFloat *)height:(NSArray

我有一个带有图像按钮的
UITableview
。当按下按钮时,它将动态添加子视图(表视图),如下图所示。我无法在下拉列表(表视图)中选择第二个选项

问题是下拉列表的高度超出了表格行。因此,我无法选择第二个选项

有人能解决这个问题吗?或者在
UITableView
中显示下拉列表

编辑:

此选项在
UITextField
下拉列表中正常工作。但在UITableView中不工作

下拉代码:

- (id)showDropDown:(UIButton *)b:(CGFloat *)height:(NSArray *)arr:(NSString *)direction {
    btnSender = b;
    animationDirection = direction;
    self.table = (UIButton *)[super init];
    if (self) {
        // Initialization code
        CGRect btn = b.frame;
        self.list = [NSArray arrayWithArray:arr];
        if ([direction isEqualToString:@"up"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y, btn.size.width, 0);
            self.layer.shadowOffset = CGSizeMake(-5, -5);
        }else if ([direction isEqualToString:@"down"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, btn.size.width, 0);
            self.layer.shadowOffset = CGSizeMake(-5, 5);
        }

        self.layer.masksToBounds = NO;
        self.layer.cornerRadius = 8;
        self.layer.shadowRadius = 5;
        self.layer.shadowOpacity = 0.5;

        table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, btn.size.width+btn.size.width, 0)];
        table.delegate = self;
        table.dataSource = self;
        table.layer.cornerRadius = 5;
        table.backgroundColor = [UIColor whiteColor];
        table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        table.separatorColor = [UIColor grayColor];
        table.separatorInset=UIEdgeInsetsZero;
        table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        if ([direction isEqualToString:@"up"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y-*height, btn.size.width, *height);
        } else if([direction isEqualToString:@"down"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, btn.size.width, *height);
        }
        table.frame = CGRectMake(0, 0, btn.size.width, *height);
        [UIView commitAnimations];
        [b.superview addSubview:self];
        [self addSubview:table];
    }
    return self;
}

-(void)hideDropDown:(UIButton *)b {
    CGRect btn = b.frame;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    if ([animationDirection isEqualToString:@"up"]) {
        self.frame = CGRectMake(btn.origin.x, btn.origin.y, btn.size.width+btn.size.width, 0);
    }else if ([animationDirection isEqualToString:@"down"]) {
        self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, btn.size.width+btn.size.width, 0);
    }
    table.frame = CGRectMake(0, 0, btn.size.width, 0);
    [UIView commitAnimations];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellText = @"Go get some text for your cell.";
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:10.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByCharWrapping];

    return labelSize.height + 20;
    //return 40;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.list count];
}


- (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.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.lineBreakMode = NSLineBreakByCharWrapping;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13.0];
    }
    cell.textLabel.text =[list objectAtIndex:indexPath.row];

    cell.textLabel.textColor = [UIColor blackColor];

    UIView * v = [[UIView alloc] init];
    v.backgroundColor = [UIColor grayColor];
    cell.selectedBackgroundView = v;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self hideDropDown:btnSender];

    UITableViewCell *c = [tableView cellForRowAtIndexPath:indexPath];


    [self myDelegate:indexPath.row];
}

- (void) myDelegate:(NSInteger) index{
    [self.delegate niDropDownDelegateMethod:self selectedIndex:index];
}
按钮
TableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


    static NSString *simpleTableIdentifier = @"quotelist";

    QuoteListCell *cell = (QuoteListCell *)[tableView dequeueReusableCellWithIdentifier: simpleTableIdentifier];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"QuoteListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    cell.quoteButton.tag=indexPath.row;
    [cell.quoteButton addTarget:self action:@selector(dropDownButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

    return cell;


}

-(void)dropDownButtonClicked:(UIButton *)sender{
    NSLog(@"searchData row at index:%d",sender.tag);
    UIButton *btn=(UIButton *)sender;

    if(dropDown == nil) {
        //[self.quoteListTableView setAllowsSelection:NO];

        CGFloat f = 200;
        dropDown = [[MyDropDown alloc]showDropDown:btn :&f :[[NSArray alloc]initWithObjects:@"Dublicate",@"Create Order", nil] :@"down"];
        dropDown.delegate = self;
    }
    else {
        //[self.quoteListTableView setAllowsSelection:YES];
        [dropDown hideDropDown:btn];
        dropDown=nil;
    }
}

你能分享添加的代码吗?下拉代码是共享的。在一段时间内增加按钮宽度。在您添加按钮的位置。并共享cellforrowatinex代码。在这种情况下,
self
是什么?它是一个
UIVIew
子类吗?共享您添加图像按钮的代码。@chidhambaram您更改了哪行?[b.superview.superview addSubview:self];不,问题是下拉列表的高度超出了表中的行。因此,我无法选择第二个选项。您有什么想法吗?向任何视图添加下拉列表时,视图高度应大于下拉列表的高度。因此,将下拉列表添加到表视图中。
- (id)showDropDown:(UIButton *)b:(CGFloat *)height:(NSArray *)arr:(NSString *)direction {
    btnSender = b;
    animationDirection = direction;
    self.table = (UIButton *)[super init];
    if (self) {
        // Initialization code
        CGRect btn = b.frame;
        self.list = [NSArray arrayWithArray:arr];
        if ([direction isEqualToString:@"up"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y, btn.size.width, 0);
            self.layer.shadowOffset = CGSizeMake(-5, -5);
        }else if ([direction isEqualToString:@"down"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, btn.size.width, 0);
            self.layer.shadowOffset = CGSizeMake(-5, 5);
        }

        self.layer.masksToBounds = NO;
        self.layer.cornerRadius = 8;
        self.layer.shadowRadius = 5;
        self.layer.shadowOpacity = 0.5;

        table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, btn.size.width+btn.size.width, 0)];
        table.delegate = self;
        table.dataSource = self;
        table.layer.cornerRadius = 5;
        table.backgroundColor = [UIColor whiteColor];
        table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        table.separatorColor = [UIColor grayColor];
        table.separatorInset=UIEdgeInsetsZero;
        table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        if ([direction isEqualToString:@"up"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y-*height, btn.size.width, *height);
        } else if([direction isEqualToString:@"down"]) {
            self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, btn.size.width, *height);
        }
        table.frame = CGRectMake(0, 0, btn.size.width, *height);
        [UIView commitAnimations];
        [b.superview.superview addSubview:self];
        [self addSubview:table];
    }
    return self;
}

I have changed one line in the above code, use this.