在UITableView UIView中的UIButton =无法点击按钮
如果我直接添加按钮,一切都很顺利。我真的很想将它添加到视图中,仍然可以点击它。这里的代码:在UITableView UIView中的UIButton =无法点击按钮
UIView *containerView =
[[[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 60)]
autorelease];
UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
footerButton.frame = CGRectMake(10, 10, 300, 40);
[footerButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[containerView addSubview:footerButton];
一切正常!在您的TableViewController中执行:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *containerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)] autorelease];
UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
footerButton.frame = CGRectMake(10, 10, 300, 40);
[footerButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[containerView addSubview:footerButton];
[footerButton setTitle:@"Touch me!" forState:UIControlStateNormal];
containerView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
self.tableView.tableFooterView = containerView;
}
- (void)click {
NSLog(@"I am here!");
}
谢谢,但不幸的是我在footerviewforsection:method中加载它 – gurghet 2010-10-15 12:58:13
这@selector(click)
看起来有点奇怪。我还以为你点击功能想是这样的:
- (void)click:(id)sender;
如果这是你所拥有的,那么你需要添加结肠@selector(click:)
使签名匹配。
我刚更改了代码以使其简短,显然不是那样 – gurghet 2010-10-15 12:55:32
您是否将页脚高度设置为要添加到视图的高度?当我在方法viewForFooterInSection中返回包含UIButton的UIView时,我遇到了类似的问题。在更新heightForFooterInSection方法之前,页脚高度不够大。例如:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return containerView.bounds.size.height;
}
如何使用'containerView'?你做'[tableView addSubview:containerView]',或者在表格视图单元格中使用它?您应该尝试使用UIButtonTypeRoundedRect并查看它是否正在进行交互。 – tia 2010-10-15 03:27:33
我在页脚中使用 – gurghet 2010-10-15 12:56:30