2

アクションを実行するボタンを含むフッターを追加するために、次のコードを追加しています。ボタンのサイズをセルのサイズに変更できません。CGRectMake(0, 0, 300,44) 値の変更は、フッターの変更に影響を与えていません。より多くのセッションを持つテーブルを使用しています。すべてのセッションのフッターが必要ない代わりに、テーブルの最後に必要なので、次のコードを挿入しました。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   
*)indexPath 
{
//...
footerView  = [[UIView alloc] init];

UIButton* Logoutbutton = [UIButton buttonWithType:UIButtonTypeCustom];

[Logoutbutton setTitle:@"Logout" forState:UIControlStateNormal];

NSLog(@"cell width : %d",cell.contentView.frame.size.width);
[Logoutbutton setFrame:CGRectMake(0, 0, 300,44)];
[Logoutbutton setBackgroundImage:[UIImage imageNamed:@"LogoutBgImage.png"] 
forState:UIControlStateNormal];
[Logoutbutton setBackgroundColor:[UIColor clearColor]]; 

[Logoutbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[Logoutbutton addTarget:self action:@selector(LogoutbuttonPressed:) 
forControlEvents:UIControlEventTouchUpInside];

Settingstable.tableFooterView = Logoutbutton;

return cell;
}

- (void)LogoutbuttonPressed: (UIButton*) button
{
 //some action
}

誰でもこの問題を解決するのを手伝ってくれますか

4

3 に答える 3

2

uitableviewにボタンを追加する必要はありません。代わりに、テーブルビューのデリゲートメソッドにビューを渡す必要があるテーブルビューのフッターにボタンを追加します:-

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

あなたと同じ要件があるので、このチュートリアルを読むことができます。ここに画像の説明を入力してください

于 2012-05-11T13:53:35.577 に答える
0

フッター ビューの高さを指定するには、次のデリゲート メソッドを使用します。

(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
于 2012-07-25T08:40:35.227 に答える