Ios UIView中的表未滚动或接收触摸
我正在制作一个应用程序,使用Ios UIView中的表未滚动或接收触摸,ios,uitableview,autolayout,uitouch,sdcalertview,Ios,Uitableview,Autolayout,Uitouch,Sdcalertview,我正在制作一个应用程序,使用SDCAlertView()及其contentView属性来显示UITableView。当我尝试在表格中滚动时出现问题 以下是我如何分配警报: SDCAlertView *soundAlertView = [[SDCAlertView alloc] initWithTitle:@"Select Sound" message:@"Select a sound." delegate:self cancelButtonTitle:@"OK" otherButtonT
SDCAlertView
()及其contentView
属性来显示UITableView
。当我尝试在表格中滚动时出现问题
以下是我如何分配警报:
SDCAlertView *soundAlertView = [[SDCAlertView alloc] initWithTitle:@"Select Sound" message:@"Select a sound." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
//Give the alert a tag for later id'ing
soundAlertView.tag = 2;
//Create the tableview controller
SelectionViewController *soundSelection = [self.storyboard instantiateViewControllerWithIdentifier:@"selectionCont"];
//assign the table to a local var
UITableView *table = soundSelection.tableView;
UIView *tableHolderView = [[UIView alloc] initWithFrame:CGRectMake(table.frame.origin.x, table.frame.origin.y, soundAlertView.contentView.frame.size.width, 200)];
[tableHolderView addSubview:table];
//Add the table view to the alert view
[soundAlertView.contentView addSubview:tableHolderView];
//Make sure the tableview fits in the alert
[soundAlertView.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableHolderView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(tableHolderView)]];
[soundAlertView show];
以下是创建表并将其添加到警报子视图的方式:
SDCAlertView *soundAlertView = [[SDCAlertView alloc] initWithTitle:@"Select Sound" message:@"Select a sound." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
//Give the alert a tag for later id'ing
soundAlertView.tag = 2;
//Create the tableview controller
SelectionViewController *soundSelection = [self.storyboard instantiateViewControllerWithIdentifier:@"selectionCont"];
//assign the table to a local var
UITableView *table = soundSelection.tableView;
UIView *tableHolderView = [[UIView alloc] initWithFrame:CGRectMake(table.frame.origin.x, table.frame.origin.y, soundAlertView.contentView.frame.size.width, 200)];
[tableHolderView addSubview:table];
//Add the table view to the alert view
[soundAlertView.contentView addSubview:tableHolderView];
//Make sure the tableview fits in the alert
[soundAlertView.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableHolderView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(tableHolderView)]];
[soundAlertView show];
然后添加约束以使tableview适合警报,然后显示警报:
SDCAlertView *soundAlertView = [[SDCAlertView alloc] initWithTitle:@"Select Sound" message:@"Select a sound." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
//Give the alert a tag for later id'ing
soundAlertView.tag = 2;
//Create the tableview controller
SelectionViewController *soundSelection = [self.storyboard instantiateViewControllerWithIdentifier:@"selectionCont"];
//assign the table to a local var
UITableView *table = soundSelection.tableView;
UIView *tableHolderView = [[UIView alloc] initWithFrame:CGRectMake(table.frame.origin.x, table.frame.origin.y, soundAlertView.contentView.frame.size.width, 200)];
[tableHolderView addSubview:table];
//Add the table view to the alert view
[soundAlertView.contentView addSubview:tableHolderView];
//Make sure the tableview fits in the alert
[soundAlertView.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableHolderView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(tableHolderView)]];
[soundAlertView show];
在做了研究之后,我发现我应该将触摸从contentView
传递到contanerView
到tableView
。虽然这会起作用,但它需要子类化,我不能子类化对contentView
属性的访问
如何让tableView
识别警报的contentView
识别的触摸和滚动
谢谢我想出来了,诀窍是将
SDCAlertView
本身子类化,然后将hitTest:
发送到tableview。设置将UITableView的属性反弹为YES,这对我来说是个问题