从滚动禁用UITableview的子视图

jhi*_*t00 1 xcode scroll subview uitableview

(xCode 4.3.2,ARC,Storyboard)像往常一样,我有一个Master/Detail项目,MasterViewController是一个UITableViewController.它顶部有一个导航栏,底部有一个工具栏.我创建了一个以编程方式加载的自定义子视图viewDidLoad.

它加载很好,并且就像我想要的那样在顶部,但是当用户滚动tableview时,子视图也会滚动.我需要子视图"坚持"到底部.

在此输入图像描述

这是我用来添加子视图的代码:

    CGRect totalFrame = CGRectMake(0, 314, 320, 58);
    UIView *totalBG = [[UIView alloc] initWithFrame:totalFrame];
    totalBG.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"totalBG.png"]];
    [self.view addSubview:totalBG];

    CGRect totalLabelFrame = CGRectMake(12, 12, 80, 40);
    totalLabelBG = [[UILabel alloc] initWithFrame:totalLabelFrame];
    totalLabelBG.backgroundColor = [UIColor clearColor];
    totalLabelBG.text = @"Total:";
    [totalLabelBG setFont:[UIFont boldSystemFontOfSize:22]];
    totalLabelBG.userInteractionEnabled = NO;
    totalLabelBG.textColor = [UIColor whiteColor];
    totalLabelBG.shadowColor = [UIColor blackColor];
    totalLabelBG.shadowOffset = CGSizeMake(0, 1);
    [totalBG addSubview:totalLabelBG];
Run Code Online (Sandbox Code Playgroud)

我尝试将userInteractionEnabled设置为NO viewDidLoad并检测触摸,并设置totalLabelBG.center属性,但都没有工作.

我还阅读了许多关于禁用网页浏览滚动的线索,但没有发现任何相关内容.

我发现另一个SOF问题的回复可能有效,也可能不行,但用户没有解释答案."诀窍是在-layoutSubviews中调整"不可滚动"子视图的框架."

jhi*_*t00 10

我通过将子视图添加到UINavigationController容器中来实现所需的结果,如下所示:

[self.navigationController.view addSubview:totalBG];
Run Code Online (Sandbox Code Playgroud)