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

iPhone模拟器在第一次触摸后挂起,iphone,objective-c,Iphone,Objective C,单击任一按钮后,应用程序将停止响应任何触摸事件。(控制器#增加/控制器#减少方法) 以下是启动时控制台的输出 [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,

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

以下是启动时控制台的输出

[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

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

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

看起来按钮(增加/减少)实际上被禁用了。在第一次“触摸”之后

e、 g.多边形未达到其最大边,因此应缺少(!)多边形

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

- (void)updateIncreaseButton{
    increaseButton.enabled = ![polygon hasMaximumSides];
}
我错过它的原因是,默认情况下,如果禁用,UIButton没有不同的样式。我的建议是,始终为UIButton的每个状态指定自定义样式,以避免类似这样的混淆


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

Controller扩展NSObject。我不知道有什么函数(可能在NSView中?)可以更新界面。在“行为正常”上添加了说明。