Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 隐藏UITableView页脚_Ios_Objective C_Uitableview_Cocoa Touch_Uikit - Fatal编程技术网

Ios 隐藏UITableView页脚

Ios 隐藏UITableView页脚,ios,objective-c,uitableview,cocoa-touch,uikit,Ios,Objective C,Uitableview,Cocoa Touch,Uikit,我无法隐藏UITableView页脚(即,将其高度设置为0并设置过渡动画) 我试图将tableView.tableViewFooter.height=0(和tableView.tableViewFooter=nil)包装在[tableView beginUpdates]和[tableView endUpdates]之间,但它不起作用 实现下面的方法将创建另一个页脚 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSec

我无法隐藏UITableView页脚(即,将其高度设置为0并设置过渡动画)

我试图将
tableView.tableViewFooter.height=0
(和
tableView.tableViewFooter=nil
)包装在
[tableView beginUpdates]
[tableView endUpdates]
之间,但它不起作用

实现下面的方法将创建另一个页脚

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


tableview页脚和节页脚之间有区别吗?我通过在我的故事板中的tableview下放置一个按钮来创建我的


有什么简单的办法吗?

这就可以了。还有其他选择,比如这个答案


最后,我给你一个最简单的解决方案。正如你所看到的,我只是把.m(为了简单起见)放在这里

表页脚和节页脚之间存在差异。您要查找的是节页脚

我还添加了一个动画块,用于添加和删除它

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

UIButton *_footerButton;


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createAndAddFooterButton];
}

-(void) buttonPressed:(id)button
{
    [UIView animateWithDuration:2 animations:^{
        self.tableView.tableFooterView = nil;
    }];
}

- (void)createAndAddFooterButton
{
    // here you create the button
    _footerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_footerButton setTitle:@"Button Title" forState:UIControlStateNormal];
    [_footerButton sizeToFit];
    [_footerButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [UIView animateWithDuration:2 animations:^{
        self.tableView.tableFooterView = _footerButton;
    }];
}

@end

使用以下方法:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0f;
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}`

好的,下面是我解决这个问题的方法

- (void)refreshTableFooterButton
{
    if (should be visible) {
        self.tableView.tableFooterView = self.tableFooterButton;
    } else {
        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
}
我使用
[[UIView alloc]initWithFrame:CGRectZero
而不是
nil
来防止不需要的空单元格出现在tableview中

我不需要动画块,但其他人可能需要

[UIView animateWithDuration:0.5 animations:^{

}];

此外,我还必须保留对我的tableFooterButton IBOutlet的强引用。这也是我最初尝试解决问题失败的部分原因。不过,我不确定对IBOutlet的强引用是否是一种好的做法。请随意对此发表评论。

使用以下代码:

self.tableView.tableFooterView?.hidden = false

我的问题是,清除线是页脚,我只能定义为1像素高,而不是0(因为我不想有页脚)。 我唯一可以修复它的方法是在ViewForFooterInstitution中提供一个视图,并将背景颜色设置为与页眉相同的颜色,这样在视觉上你不会注意到,并且当我在新行中设置动画时,它们不会显示通过页眉顶部的清晰线(页脚)所在位置


使用tableview委托方法&在那里设置高度0。或者放一些代码。@Nico tableview页脚和节页脚之间有区别吗?因为使用此方法会创建另一个页脚。tableview页脚和节页脚之间有区别吗?因为使用此方法会创建另一个页脚。没有区别nce。这个页脚应该不会被注意到,你能提供一个屏幕截图吗?也试着将它设置为0,看看它是如何运行的。我没有足够的声誉在这里发布一个图像,但在这里它的返回值是50。现在我从你那里得到一个问题,你想有一个页脚吗?而对
IBOutlet
的强烈引用是不可能的标准模式在本例中保留强引用是可以的,因为您可能稍后会将同一个视图重新放回视图层次结构中。强引用避免了以某种方式重新创建视图。叮叮我们有一个赢家
self.tableView.tableFooterView?.hidden = false
    override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let blankView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 1))
    blankView.backgroundColor = {Same colour as Header}
    return blankView