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 添加按钮,而是将其添加到 tableview 的页脚,您必须将视图传递给 tableview 的委托方法:-

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

您可以阅读本教程,因为它与您的要求相同。在此处输入图像描述

于 2012-05-11T13:53:35.577 回答
0

用这种方式作为tableview的页脚

self.tableView.tableFooterView = myCustomFooterView

对于整个表格的页脚视图,请使用

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

并在此处阅读有关它的更多信息

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html

如果您不想只有一个单元格的页脚,则实现一个自定义单元格,并使用 layoutsubviews 更改单元格设置,对于自定义单元格,请使用此链接

http://www.e-string.com/content/custom-uitableviewcells-interface-builder

http://www.galloway.me.uk/tutorials/custom-uitableviewcell/

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

于 2012-05-11T13:39:01.123 回答
0

要提供页脚视图高度,请使用此委托方法:

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