【问题标题】:One uiview stop working when interacting with another一个 uiview 在与另一个交互时停止工作
【发布时间】:2012-08-08 18:08:57
【问题描述】:

在同一个 UIViewController 上,NSTimer 每 0.01 秒更新一个 UILabel。在同一个 Controller 中,有一个 UIView 包含来自另一个 .nib 的 TableController。

当我滚动表格时,UILabel 会停止更新,直到滚动完成。有什么想法吗?

提前致谢。

【问题讨论】:

    标签: iphone ios uiview uiviewcontroller


    【解决方案1】:

    您应该使用“NSRunLoopCommonModes”或“UITrackingRunLoopMode”模式注册您的计时器。

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timer) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    
    - (void)timer
    {
        label.text = @"different text";
    }
    

    阅读NSRunLoop Class ReferenceThreading Programming GuideConcurrency Programming Guide

    【讨论】:

    • 这是一个完美的答案。该解决方案就像一个魅力,并且消息来源解释并帮助我理解了原因。非常感谢
    【解决方案2】:

    将标签更新代码放在线程中。它应该可以解决您的问题。

    【讨论】:

    • 你以前尝试过这种方法吗?
    • 没有。我已经应用了概念。由于线程是独立的,所以它不应该影响它的方法..
    猜你喜欢
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2012-12-09
    • 2021-05-30
    • 1970-01-01
    • 2017-08-02
    相关资源
    最近更新 更多