在iOS中:无法触摸子视图中的UITableview
我有一个UITableview
与图像按钮。当点击按钮时,它将动态添加子视图(表格视图),如下图所示的下拉列表。我无法选择下拉列表中的第二个选项(表格视图)。在iOS中:无法触摸子视图中的UITableview
问题是下拉高度超过了表格行,所以我无法选择第二个选项。
任何人都有解决方案吗?或任何想法显示在UITableView
下拉?
。
编辑:
这UITextField
做工精细dropdown.but不是在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;
}
}
- (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.
你改变了哪一行? – Chidhambaram 2014-09-25 06:32:22
[b.superview.superview addSubview:self]; – 2014-09-25 06:32:57
是你的问题解决了。@ Chidhambaram – 2014-09-25 06:39:18
你可以分享添加下拉 – 2014-09-25 05:39:06
下拉代码的代码是共享的。 – Chidhambaram 2014-09-25 06:00:06
一段时间增加按钮宽度。并且在那里添加了按钮。并且还分享了cellforrowatindex代码的代码。 – 2014-09-25 06:04:55