gpt4 book ai didi

iphone - 将按钮添加到 viewForFooterSection UITableView

转载 作者:行者123 更新时间:2023-11-28 18:43:29 25 4
gpt4 key购买 nike

经过对 this topic 的讨论我正在尝试在 UItableView 的页脚 View 上实现 2 个按钮。为了创建按钮,我在声明 .h 文件中声明它们,在实现 .m 文件中合成它们,然后,我通过代码创建它们,如下所示:

- (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 委托(delegate)方法中:

- (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];

}

最佳答案

我认为您缺少的是 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

如果没有这个,自定义页脚的高度将为 0。您仍然可以看到按钮的原因是 clipsToBounds 对于自定义 View 默认为 NO

关于iphone - 将按钮添加到 viewForFooterSection UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8302713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com