【发布时间】:2011-11-28 21:38:49
【问题描述】:
在对this topic 进行了一些讨论之后,我正在尝试在 UItableView 的页脚视图上实现 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 委托方法中:
- (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];
}
【问题讨论】:
-
示例代码看起来不错。你检查过action方法中的代码吗?
-
我刚刚在我的原始帖子中添加了它。但是点击按钮甚至没有变成蓝色......??
-
如果我直接添加按钮,没有包含“customview”的按钮执行操作,但它们被水平拉伸并垂直收缩。我尝试实现 [customView bringSubViewTofront... 但它也不起作用。
标签: iphone ios uitableview uiscrollview