views:

206

answers:

2

The application will stop responding to any touch events after clicking on either button. (Controller#increase / Controller#decrease methods).

Here is the output of the console on startup

[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)

Running the application on debug mode I see that there is indeed a call on the corresponding method as well as updating the UI. So the method does reach to the end of it and returns.

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

However removing the call

[self updateInterface];

the application behaves normally (e.g. touch events are handled) but of course not according to specification :).

Program code follows

//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
A: 

I am not a 100% sure but doesn't the update interface function get's called x amount of times per second? If so wouldn't that make unnecessary to have to tell the interface to update after each touch event? Does the application behave as expected if you remove the two [self updateInterface]; calls in the event handlers?

Annerajb
Controller extends NSObject. I'm not aware of a function (maybe in NSView?) that updates the interface. Clarification added on "behaves normally".
Cue
A: 

As pointed out by a member in another forum the problem is actually a "logic" one.

It seems that the buttons (increase/decrease) were actually disabled. After the first "touch".

e.g. the polygon hasn't reached its maximum sides hence it should a NOT(!) is missing

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

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

The reason I missed it is that by default, UIButton doesn't have a different style if disabled. My piece of advice, always specify a custom style for each state of a UIButton to avoid confusion such as this.

You can do this in Interface Builder. With a UIButton widget selected choose Tools -> Attributes Inspector.

Cue