代码之家  ›  专栏  ›  技术社区  ›  JosephH

performSelector afterD时未发生排队视图更新elay:0 used

  •  0
  • JosephH  · 技术社区  · 14 年前

    我有一个应用程序,它可以根据到达套接字或本地用户交互的数据执行一些计算。

    spinner = [[UIActivityIndiactorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [spinner setCenter:self.view.center];
    [self.view addSubview:spinner];
    [spinner startAnimating];
    [self performSelector:@selector(doCalcs) withObject:nil afterDelay:0];
    

    这很有效,除非代码是由于通过网络到达的消息而运行的。我在用 http://code.google.com/p/cocoaasyncsocket/ 来处理套接字,并且代码正在onS中运行ocket:didReadData:withTag:方法。

    如果我以后换衣服elay:0 to 后Delay:1 then 微调器在doCalcs运行的整个过程中都会出现,但缺点是它需要额外的一秒钟。因此,代码似乎都是正确的,但无论出于什么原因,微调器都没有机会在doCalcs运行之前进入屏幕。

    任何建议都欢迎。

    2 回复  |  直到 14 年前
        1
  •  1
  •   Jason Jenkins    14 年前

    您可以尝试在背景线程上执行计算,以防止动画阻塞:

    [self performSelectorInBackground:@selector(doCalcs)withObject:nil];
    
        2
  •  0
  •   gnasher    14 年前