【发布时间】:2013-04-12 07:38:01
【问题描述】:
我有一个类似于this one 的问题,但提供的答案并没有多大帮助。
我有UITableView 和一些自定义UITableViewCells,这些单元格有一些嵌套的自定义UIViews,最后是一些UIButtons。如上所述,问题是当我触摸按钮时,触摸事件不会填充到UITableView,并且它永远不会滚动。
这是一些代码(这只是最快的重现方式,不是我的实际代码):
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView * tableView;
@end
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,
self.view.bounds.size.width,
self.view.bounds.size.height)
style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[UITableViewCell alloc] init];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor redColor];
button.frame = CGRectMake(0, 0, 50, 44);
[cell.contentView addSubview:button];
return cell;
}
@end
唯一单元格中的红色按钮不会让表格视图反弹滚动。
谁能帮帮我?
附:不要注意我提供的代码的愚蠢性,我知道有关它的所有问题。我只是提供它来显示问题的全部内容。是buttonView和scrollView的冲突。
【问题讨论】:
标签: ios uitableview uibutton