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

iPhone模拟器在第一次触摸后挂起

  •  0
  • qnoid  · 技术社区  · 15 年前

    点击任一按钮后,应用程序将停止响应任何触摸事件。(控制器增加/控制器减少方法)。

    这是启动时控制台的输出

    [Session started at 2009-10-04 14:41:20 +0300.]
    GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Fri Jul  3 01:19:56 UTC 2009)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
    Attaching to process 1340.
    Pending breakpoint 1 - ""Controller.m":46" resolved
    2009-10-04 14:41:23.339 HelloPoly[1340:207] My polygon: Hello I am a 5-sided polygon (aka a Pentagon) with angles of 108 degrees (1.884956 radians).
    (gdb) 
    

    在调试模式下运行应用程序,我发现确实有对相应方法的调用,并且更新了UI。所以这个方法到达了它的末尾并返回。

    2009-10-04 14:42:25.723 HelloPoly[1340:207] sides increased to 6
    

    但是,取消呼叫

    [self updateInterface];
    

    应用程序的行为正常(例如处理触摸事件),但当然不符合规范:)。

    程序代码如下

    //Controller extends NSObject
    
    #import "Controller.h"
    
    @implementation Controller
    
    
    - (void)awakeFromNib { // configure your polygon here
        polygon.minimumNumberOfSides = 3;
        polygon.maximumNumberOfSides = 12;
        polygon.numberOfSides = numberOfSidesLabel.text.integerValue;
    
        NSLog (@"My polygon: %@", polygon);
    }
    
    - (void)updateDecreaseButton{
        decreaseButton.enabled = [polygon hasMinimumSides];
    }
    
    - (void)updateIncreaseButton{
        increaseButton.enabled = [polygon hasMaximumSides];
    }
    
    - (void)updateNumberOfSidesLabel{
        numberOfSidesLabel.text = [NSString stringWithFormat:@"%i", polygon.numberOfSides];
    }
    
    - (void)updateInterface {
        [self updateDecreaseButton];
        [self updateIncreaseButton];
        [self updateNumberOfSidesLabel];
    }
    
    - (IBAction)decrease:(id)sender {
        NSLog(@"sides decreased to %i", [polygon decreaseSides]);
        [self updateInterface];
    }
    
    - (IBAction)increase:(id)sender {
        NSLog(@"sides increased to %i", [polygon increaseSides]);
        [self updateInterface];
    }
    @end
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   qnoid    15 年前

    正如另一个论坛的一位成员所指出的,这个问题实际上是一个“逻辑”问题。

    按钮(增加/减少)似乎已被禁用。在第一次“触摸”之后。

    例如,多边形没有达到其最大边,因此它应该 不是 (!)遗失

    - (void)updateDecreaseButton{
        decreaseButton.enabled = ![polygon hasMinimumSides];
    }
    
    - (void)updateIncreaseButton{
        increaseButton.enabled = ![polygon hasMaximumSides];
    }
    

    我错过它的原因是,默认情况下,如果禁用uibutton,它没有不同的样式。我的建议是,始终为uibutton的每个状态指定一个自定义样式,以避免这样的混淆。

    您可以在Interface Builder中执行此操作。选择uibutton小部件后,选择“工具”->“属性检查器”。

        2
  •  0
  •   Annerajb    15 年前

    我不是百分之百确定,但更新接口函数不是每秒调用x次吗?如果是这样,那么在每次触摸事件之后,就不需要告诉界面更新了吗?如果删除两个[self-updateinterface];事件处理程序中的调用,应用程序的行为是否如预期的那样?