【问题标题】:resize Footer in UItableview在 UItableview 中调整页脚大小
【发布时间】:2012-05-11 13:37:00
【问题描述】:

我正在添加以下代码来添加带有按钮的页脚以执行操作。我无法将按钮重新调整为单元格的大小。 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
}

谁能帮我解决这个问题

【问题讨论】:

    标签: iphone ios uitableview table-footer


    【解决方案1】:

    您不需要向 uitableview 添加按钮,而是将其添加到 tableview 的页脚,您必须将视图传递给 tableview 的委托方法:-

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

    您可以阅读此tutorial,因为它与您的要求相同。

    【讨论】:

      【解决方案2】:

      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

      【讨论】:

      • 这为每个会话权创建了页脚。我只需要在 UITable 视图的最后一行末尾显示一个单页脚
      • 是的,我在自定义视图中添加了一个按钮并将其分配给页脚,但现在发生的情况是单击时按钮的功能操作没有被调用
      • 查看按钮的xib连接,可能会被移除
      • 哎呀我没有使用 xib。它是调用动作的@selector
      • 呵呵,那它必须调用函数,清理你的项目
      【解决方案3】:

      要给页脚视图高度使用这个委托方法:

      (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-27
        • 2012-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多