添加为footerview时,UIButton没有响应

时间:2012-06-22 05:51:36

标签: iphone ios uitableview ios4 uibutton

我的按钮没有响应触摸事件,请找到如下代码段。

我已将UIButton添加到UIView并将UIView设置为UITableView's页脚视图。

请让我知道并谢谢。

CGRect tblViewFrame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, 300);

self.tblViewSettings = [[[UITableView alloc]initWithFrame:tblViewFrame style:UITableViewStyleGrouped]autorelease];
self.tblViewSettings.backgroundColor = [UIColor clearColor];
self.tblViewSettings.showsVerticalScrollIndicator = FALSE;
self.tblViewSettings.delegate = self;
self.tblViewSettings.dataSource = self;
self.tblViewSettings.scrollEnabled = YES;

// Set the background color
self.view.backgroundColor = [UIColor clearColor];

UIView *buttonView = [[[UIView alloc]initWithFrame:CGRectMake(10,10, 320, 60)]autorelease];
self.signoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.signoutButton.frame = CGRectMake(10,10, 300, 40);
UIImage *image = [[UIImage imageNamed:@"btn-large1.png"] stretchableImageWithLeftCapWidth:22 topCapHeight:0];
NSString *strSignOut = NSLocalizedString(@"Sign Out", @"SignOut Button");
[self.signoutButton setTitle:strSignOut forState:UIControlStateNormal];
[self.signoutButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.signoutButton.titleLabel.shadowOffset = CGSizeMake(0, -1);
[self.signoutButton setBackgroundImage:image forState:UIControlStateNormal];
self.signoutButton.titleLabel.font = [UIFont boldSystemFontOfSize:20.0];
[self.signoutButton addTarget:self action:@selector(signOutBtnTapped:) forControlEvents:UIControlEventTouchUpInside];

buttonView.backgroundColor = [UIColor clearColor];

[buttonView addSubview:self.signoutButton];
buttonView.userInteractionEnabled = YES;
//[self.view addSubview:buttonView];
self.tblViewSettings.tableFooterView = buttonView;

self.tblViewSettings.tableFooterView.userInteractionEnabled = YES;

[self.view addSubview:self.tblViewSettings];

-(IBAction)signOutBtnTapped:(id)sender{
}

3 个答案:

答案 0 :(得分:0)

我查看了您的代码并将其应用到我的项目中。实际上它有效。我没有改变你的代码。我想你必须检查表格视图和底部视图的框架,因为其他一切正常。

答案 1 :(得分:-1)

尝试在

中捕获UIControlEventTouchDown而非UIControlEventTouchUpInside的事件

[self.signoutButton addTarget:self action:@selector(signOutBtnTapped:) forControlEvents: UIControlEventTouchUpInside];

其他一切似乎都没问题。

答案 2 :(得分:-1)

用于在页脚视图部分

中添加按钮
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView* customView;

customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 60.0)];

UIButton *Login_Btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [Login_Btn setImage:[UIImage imageNamed:@"btn_login.png"] forState:UIControlStateNormal];

Login_Btn.frame = kiPhoneButtonFrame;

[customView addSubview:Login_Btn];
[Login_Btn addTarget:self 
                      action:@selector(Login_Btn_Clicked:)
            forControlEvents:UIControlEventTouchUpInside];

return customView;
}

按钮单击方法

-(IBAction)Login_Btn_Clicked:(id)sender
{
     // Code for button CLick which you want to do.
}