-1

ボタンがタッチ イベントに応答しません。以下のコード スニペットを見つけてください。

フッタービューに追加UIButtonUIViewて設定し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{
}
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の代わりにUIControlEventTouchUpInsideイベントをキャプチャしてみてください

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

他のすべては問題ないようです。

于 2012-06-22T06:23:03.343 に答える