-1

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

我已添加UIButtonUIView设置UIViewUITableView'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{
}
4

3 回答 3

0

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

于 2012-06-22T06:57:14.427 回答
-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.
}
于 2012-06-22T06:31:48.687 回答
-1

尝试捕获事件 UIControlEventTouchDown而不是UIControlEventTouchUpInsidein

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

其他一切似乎都还可以。

于 2012-06-22T06:23:03.343 回答