首页 \ 问答 \ 如果我在UITabBar之间切换UIViewController,则无法滚动回顶部(Can't scroll back to top, if I switch between UIViewController with UITabBar)

如果我在UITabBar之间切换UIViewController,则无法滚动回顶部(Can't scroll back to top, if I switch between UIViewController with UITabBar)

我有我的UIScrollView问题,如果我点击一个标签栏项目切换到其他ViewController,然后回到ViewController与UIScrollView我不能回滚到顶部。 我必须在ViewControllers之间再次切换,然后正确显示UIScrollView的内容。 这个过程对于用户来说真的很不舒服。 这是我的代码:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self becomeFirstResponder];  // View as first responder

    scrollView.scrollEnabled = YES;
    [scrollView setUserInteractionEnabled:YES];
    testLabel.text = @"there is a long, long text normally";   
}

我没有特意设置contentSize,因为UIScrollView根据这个标签自动获得正确的高度。 我的问题是如果我向下滚动,然后切换到另一个ViewController,当我再次回到这个屏幕时,我不能再滚动到顶部。

一些进一步的信息:自动布局使用,层次结构是:ViewController - 查看 - UIScrollView - 标签,...


I have an issue with my UIScrollView, if i click on a tab bar item to switch to an other ViewController and then go back to the ViewController with the UIScrollView i can't scroll back to the top. I have to switch again between ViewControllers and then the content in the UIScrollView is correctly shown. This procedure is really uncomfortable for the user. This is my code:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self becomeFirstResponder];  // View as first responder

    scrollView.scrollEnabled = YES;
    [scrollView setUserInteractionEnabled:YES];
    testLabel.text = @"there is a long, long text normally";   
}

I didn't set the contentSize on purpose, because the UIScrollView automatically gets the correct height depending on this label. My Problem is if i scroll down and then switch to an other ViewController, when I'm coming back again to this screen I can't scroll up to the top anymore.

Some further information: Auto Layout used, Hierarchy is: ViewController - View - UIScrollView - Label, ...


原文:https://stackoverflow.com/questions/14661606
更新时间:2023-11-04 13:11

最满意答案

我无法找到一种简单的方法来使用内置的百里香对象/方法来完成此操作,但这会起作用(即使这有点痛苦)。

调节器

@GetMapping
public String page(Map<String, Object> model) {
    .
    .
    DecimalFormat f = new DecimalFormat("#");
    f.setRoundingMode(RoundingMode.FLOOR);
    model.put("format", f);
    .
    .
}

<th:block th:with="n=${2.54}">
    <!-- outputs 2 -->
    <span th:text="${format.format(n)}" />
</th:block>

I can't find a simple way to do this with the built in thymeleaf objects/methods, but this will work (even if it's a little painful).

Controller

@GetMapping
public String page(Map<String, Object> model) {
    .
    .
    DecimalFormat f = new DecimalFormat("#");
    f.setRoundingMode(RoundingMode.FLOOR);
    model.put("format", f);
    .
    .
}

Page

<th:block th:with="n=${2.54}">
    <!-- outputs 2 -->
    <span th:text="${format.format(n)}" />
</th:block>

相关问答

更多
  • Thymeleaf具有相当于 :thymeleaf 2.0中引入的th:switch和th:case属性。 他们按照您的预期工作,使用*作为默认情况:

    User is an administrator

    User is a manager

    User i ...

  • 这对我有用: This works for me:
  • 我希望你从中获得一些东西。 首先将数字转换为字符串,然后使用substr()拆分数字,然后再将分割值转换为整数: $num = 23; $str_num = (string)$num; $var1 = (int)substr($str_num, 0, 1); $var2 = (int)substr($str_num, 1, 1); 或使用纯数字: $num = 23; $var2 = $num % 10; $var1 = ($num - $var2) / 10; I hope you get som ...
  • 我前段时间已经解决了这个问题,所以我想与解决方案分享会很好。 我已经使用包装器将映射更改为控制器中的列表,因此它是List,其中ProductQuantity类包含2个字段 - 产品和字符串数量。 之后我将该列表转换为映射并保存到数据库中。 I've solved this problem some time ago, so I guess it would be nice to share with the solution. I've changed map to list in controller ...
  • 要限制可以在输入标记中输入的字符长度,可以使用maxlength属性。 要将输入限制为数字,您需要编写一个javascript函数,将其与输入标记绑定。 记得 Thymeleaf是一个Java库。 它是一个XML / XHTML / HTML5模板引擎(可扩展到其他格式),可以在Web和非Web环境中工作。 它更适合在Web应用程序的视图层提供XHTML / HTML5,但它甚至可以在脱机环境中处理任何XML文件。 引自Thymeleaf主页 Thymeleaf不负责的是用户如何与html页面交互。 例如按 ...
  • 您需要从select元素中删除th:object属性,并仅为表单保留一个,因为Thymeleaf文档指出: 一旦进入标签,就不能指定其他th:object属性。 这与HTML表单不能嵌套的事实一致。 th:object表单上的th:object属性然后需要引用一个支持form的bean,即可以存储通过表单发送的任何值的对象,例如provincia 目前你正在尝试访问List对象的属性provincia ,它根本不存在。 You need to remove th:object attribute from ...
  • 您可以使用Thymeleaf( API )的#numbers实用程序并相应地设置数字。 th:value="${#numbers.formatDecimal(product.number, 2, 3)}" 这设置了最小整数数字(上面的2)和精确的十进制数字(上面的3)。 对于分隔符,可以直接指定它: th:value="${#numbers.formatDecimal(product.number, 2, 3,'COMMA')}" 分隔符选项是POINT , COMMA , WHITESPACE , N ...
  • 我无法找到一种简单的方法来使用内置的百里香对象/方法来完成此操作,但这会起作用(即使这有点痛苦)。 调节器 @GetMapping public String page(Map model) { . . DecimalFormat f = new DecimalFormat("#"); f.setRoundingMode(RoundingMode.FLOOR); model.put("format", f); . . } ...
  • 您可以使用子字符串来提取脚本的第一个参数的第一个字符: if [ ${1:0:1} -lt 7 ]; then echo "The first digit is smaller than 7" fi 要为每个角色执行此操作,您可以使用循环: for (( i = 0; i < ${#1}; ++i )); do if [ ${1:$i:1} -lt 7 ]; then echo "Character $i is smaller than 7" fi done 注意 ...
  • 如果您没有递归方法的问题,那么这里是一个解决方案,您的代码几乎没有变化: - def get_digit(num): if num < 10: print(num) else: get_digit(num // 10) print(num % 10) 用法 >>> get_digit(543267) 5 4 3 2 6 7 If you don't have problem with recursion approach then here ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)