1

我有一些注册表单,其中电子邮件和登录文本字段作为表格单元格,注册按钮作为页脚视图中的按钮。一切都很好,这是代码

frame = CGRectMake(boundsX+85, 100, 150, 60);
    UIButton *signInButton = [[UIButton alloc] initWithFrame:frame];
    [signInButton setImage:[UIImage imageNamed:@"button_signin.png"] forState:UIControlStateNormal];
    [signInButton addTarget:self action:@selector(LoginAction) forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.hidesBackButton = TRUE;
    self.tableView.tableFooterView.userInteractionEnabled = YES;
    self.tableView.tableFooterView = signInButton;
    self.view.backgroundColor = [UIColor blackColor];

我的问题是如何在这个按钮旁边添加另一个按钮。

通过使用 [self.tableView.tableFooterView addSubview:...] 按钮未显示,如果我使用其他一些 UIView,将按钮放在那里,然后说 footerView 是 UIView,我看到按钮,但无法按下它们.

我希望这不会太令人困惑,并且您理解我的问题。

4

4 回答 4

1

如果您按照您所说的尝试将按钮添加到按钮的子视图中,那么您的第一次尝试是错误的:

首先你

... 
self.tableView.tableFooterView = signInButton;
...

然后稍后

... 
[self.tableView.tableFooterView addSubview:...]
...

但 tableFooterView 是 signInButton。所以这就是为什么这不起作用。

您的第二次尝试是正确的,而 yonanderson 指出您应该锻炼的答案是正确的方法,您只需要:

[yourButtonsView addSubView:button1];
[yourButtonsView addSubView:button2];
yourButtonsView.userInteractionEnabled = YES;
self.tableView.tableFooterView = yourButtonsView;
self.tableView.tableFooterView.userInteractionEnabled = YES;
于 2009-12-09T18:09:40.073 回答
1

看看这个问题:UIButtons on tableFooterView not respond to events

于 2009-12-08T15:55:52.637 回答
0

我花了很长时间才弄清楚为什么我的页脚按钮没有调用指定的操作。最后我发现我需要调整页脚的高度。这为我修复了它:

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return footerView.bounds.size.height;
}
于 2010-05-20T19:22:21.103 回答
0

嗯,在回答之前我没有仔细阅读这个。我认为您需要设置容器 UIView 的userInteractionEnabled属性,然后在尝试时将 footerView 设置为带有子视图的容器。

于 2009-12-08T13:14:10.620 回答