Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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被隐藏时,如何使UIScrollView占据屏幕高度?_Ios_Objective C_Uitableview_Uiscrollview - Fatal编程技术网

Ios 当底部的UITableView被隐藏时,如何使UIScrollView占据屏幕高度?

Ios 当底部的UITableView被隐藏时,如何使UIScrollView占据屏幕高度?,ios,objective-c,uitableview,uiscrollview,Ios,Objective C,Uitableview,Uiscrollview,我有一个UIView,它有两个子元素:上半部分是UIScrollView(它包含两个UILabels),底部是UITableView。这基本上是一个字典,滚动视图的目的是显示单词和定义,表视图用于显示相关单词。并非字典中的所有单词都有关联的单词数组,因此当数组为空时,我会隐藏UITableView 但是,当UITableView被隐藏时,我无法让UIScrollView填充整个父视图。以下是我迄今为止所尝试的: - (void)updateUIWithWord:(NSString *)theWo

我有一个
UIView
,它有两个子元素:上半部分是
UIScrollView
(它包含两个
UILabel
s),底部是
UITableView
。这基本上是一个字典,滚动视图的目的是显示单词和定义,表视图用于显示相关单词。并非字典中的所有单词都有关联的单词数组,因此当数组为空时,我会隐藏
UITableView

但是,当
UITableView
被隐藏时,我无法让
UIScrollView
填充整个父视图。以下是我迄今为止所尝试的:

- (void)updateUIWithWord:(NSString *)theWord
           andDefinition:(NSString *)theDefinition
    andRelatedWordsArray:(NSArray *)theRelatedWordsArray {
    self.navigationItem.title = theWord;
    self.word.text = theWord;
    self.definition.text = theDefinition;
    self.relatedWordsArray = theRelatedWordsArray;

    if (![relatedWordsArray count]) {
        relatedWordsTableView.hidden = YES;

        // set the UITableView's width and height to 0 just to be sure
        // I feel this isn't needed though
        CGRect relatedWordsTableViewFrame;
        relatedWordsTableViewFrame.size = CGSizeMake(0, 0);
        relatedWordsTableView.frame = relatedWordsTableViewFrame;

        // then make the scroll view occupy the remaining height;
        // that is, the self.view's actual height
        CGRect scrollViewFrame;
        scrollViewFrame.origin = CGPointMake(0, 0);
        scrollViewFrame.size = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
        scrollView.frame = scrollViewFrame;
    }
}
简单地说,这是行不通的。对于任何没有相关单词和很长定义的单词,滚动视图只是占据了相同的高度,即使没有了表视图。帮忙


ADD:我尝试修复
UIScrollView
中的约束,使其相对于
UITableView
的顶部,而不是具有固定的高度,但这似乎是不可能的。

您有一个“if”和一个“else”。其中只有一个将被执行。因此,当“if”部分运行并且
relatedWordsTableView.hidden
设置为YES时,表视图将被隐藏,但不会发生其他任何事情。“else”部分没有运行,因此没有发生任何事情。

以不同的方式处理问题。我让
UIScrollView
占据整个屏幕,并将
UITableView
放在它里面,在我的两个标签下面,禁用滚动。现在我可以隐藏并显示它。

你确定所有的
IBOutlet
s都连接好了吗?是的,所有的IBOutlet都连接正确了。哇,我真不敢相信我犯了那个错误。将所有内容从else块移动到if块,并将else全部删除。但仍然不起作用。那么现在发生了什么?(再说一遍,你确定这段代码正在运行吗?)