简体   繁体   English

iOS-使用自定义UI TableViewCell作为TableFooter

[英]IOS - Use Custom UI TableViewCell as TableFooter

I have setup a UITableViewController with various custom cells - one of which is a submit button - which I need to appear once at the foot of the table. 我已经设置了一个带有各种自定义单元格的UITableViewController-其中之一是一个提交按钮-我需要在表格底部出现一次。

the cell has the following identifier - 该单元格具有以下标识符-

 UITableViewCell *headerView = [tableView dequeueReusableCellWithIdentifier:@"ButtonTableViewCell"];

Can anyone advise on how I could apply this cell once at the foot of my table? 有人可以建议我如何在桌子脚下应用此单元格吗? It needs to access a segue also. 它还需要访问segue。

I considered using the 我考虑使用

  -(void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { 

method, but not sure how or if I could apply my cell in this way as that method doesnt return anything? 方法,但不确定如何或是否可以以这种方式应用单元格,因为该方法不会返回任何内容?

willDisplayFooterView is only called when this particular event happens. 仅在发生此特定事件时才会调用willDisplayFooterView I don't think that is relevant to you in this case. 在这种情况下,我认为这与您无关。

You can assign a view to the footerView property of your table. 您可以将视图分配给表的footerView属性。 Or you can increase the numberOfRowsInSection count to whatsoever you have in there now plus 1. 或者,您可以将numberOfRowsInSection计数增加到现在所拥有的任何值加1。

Then you add a condition to the cellForRowAtIndexPath method to find out if it's the last cell and use your headerView cell instead of your normal table cell. 然后,将条件添加到cellForRowAtIndexPath方法中,以找出它是否是最后一个单元格,并使用headerView单元格而不是普通表单元格。

Use the delegate methods: 使用委托方法:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

For viewForFooterInSection return any view you want (it could be a UITableViewCell if you want to reuse that view, and add the some target to the view button). 对于viewForFooterInSection,返回您想要的任何视图(如果您想重用该视图,则可以是UITableViewCell,并将某些目标添加到视图按钮)。

Just to give you an idea, here is an example: 只是为了给您一个想法,下面是一个示例:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"Button" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchUpInside];

    return button;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 40;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM