经过一些关于this topic的讨论我正试图在UItableView的footerview上实现2个按钮。要创建按钮,我把它们申报的声明.h文件中,对实施.m文件合成,然后,我通过代码创建它们,就像这样:添加按钮viewForFooterSection UITableView
- (UIButton *)resetButton{
if (resetButton == nil)
{
resetButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
resetButton.frame = CGRectMake(20.0, 40 , 95.0, 37.0);
[resetButton setTitle:@"Reset" forState:UIControlStateNormal];
resetButton.backgroundColor = [UIColor clearColor];
[resetButton addTarget:self action:@selector(resetAction:) forControlEvents:UIControlEventTouchDown];
resetButton.tag = 1;
}
return resetButton;
}
,然后,我实现了这个代码进入UITableView的委托方法:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 100.0)];
[customView addSubview:self.resetButton];
[customView addSubview:self.calculateButton];
return [customView autorelease];
}
通过这样做,该按钮出现在屏幕上。然而,当我点击他们,什么都不会发生(我实现的行动AlertView检查,如果他们的工作
任何帮助。这里?
谢谢!
编辑:链接到该按钮的动作:
-(IBAction)resetAction:(id)sender {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Reset"
message:@"You just pressed the Reset button"
delegate:self
cancelButtonTitle:@"Acknowledged"
otherButtonTitles:nil];
[alert show];
[alert release];
}
示例代码看起来没问题。你是否检查过动作方法中的代码? – benwong
我只是将它添加到我的原始帖子中。但按钮甚至从窃听中变成蓝色......? – Marcal
如果我直接添加按钮,没有包含“customview”的按钮,按钮将执行这些操作,但它们会水平拉伸并垂直收缩。我试图实现[customView bringSubViewTofront ...但它也不起作用。 – Marcal