iPhone hello world unresponsive

6 views
Skip to first unread message

stuntmouse

unread,
Sep 7, 2009, 11:39:06 PM9/7/09
to Programming Nu
I'm having trouble with the Nu iPhone hello world example at [1].

Everything loads and displays correctly, but the application is
unresponsive in the simulator.

My setup:

OS X 10.5.8

Nu 0.3.3

iPhone SDK - compiling for simulator with 2.0 version of the SDK

[1]
http://neontology.com/posts/2008/03/06/NuHelloWorldClassic

stuntmouse

unread,
Sep 8, 2009, 12:27:36 AM9/8/09
to Programming Nu
Replying to my own message:

I was able to get a responsive UIAlertView message popup, but I'm
still not sure what's up with the button and textfield.

XCode version 3.1.

Tim Burks

unread,
Sep 8, 2009, 8:35:10 PM9/8/09
to program...@googlegroups.com
I haven't tried this in a while and suspect that an API change could
be causing your problem.

I've noticed that UIKit and Cocoa objects tend to fail silently when
they aren't configured as expected, this is a regular source of
frustration. I suggest you try using (UIButton buttonWithType:) to
create your button and keep in mind that you'll have to declare any
UIButtonType constants that you use. Here's the declaration from the
Xcode docs:

typedef enum {
UIButtonTypeCustom = 0,
UIButtonTypeRoundedRect,
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
} UIButtonType;

Tim

stuntmouse

unread,
Sep 8, 2009, 9:58:59 PM9/8/09
to Programming Nu

Thanks for the suggestion, but the button is still unresponsive
visually, and doesn't trigger an action when hit. This is true on the
simulator and the phone.

I've pasted my code below. It's very minimalistic now. You'll see a
popup after the button is loaded to the view. You should see another
popup when the button is pressed, but I never do.

I'm now using the latest SDK.

;;; code.m


(global UIControlEventTouchUpInside (<< 1 6))
(global UIControlEventTouchDown 1)

(global UIButtonTypeRoundedRect 1)


(function raise-alert (msg del)
(let
((my-alert (UIAlertView alloc)))
(my-alert initWithTitle:msg message:msg delegate:del
cancelButtonTitle:"OK" otherButtonTitles:nil)
(my-alert show)))

(class HelloWorldClassicAppDelegate is NSObject
(ivar (id) window)


;; This method is invoked when the Hello button is touched
(- (void)hello:(id)sender is
(raise-alert "It's alive!" self))


(- (void)applicationDidFinishLaunching:(id)application is
;; Set up the window and content view
(set screenRect ((UIScreen mainScreen) bounds))
(set @window ((UIWindow alloc) initWithFrame:screenRect))

;; Add the image as the background view
(set anImageView ((UIImageView alloc) initWithFrame:((UIScreen
mainScreen) applicationFrame)))

(set button (UIButton buttonWithType:UIButtonTypeRoundedRect))
(button setFrame: (list 120 200 80 40))

(button addTarget:self action:"hello:"
forControlEvents:UIControlEventTouchDown) ;; hello: is sent when the
button is touched

(anImageView addSubview:button)
(raise-alert "button added" self)

(@window addSubview:anImageView)

;; Show the window
(@window makeKeyAndVisible)))

stuntmouse

unread,
Sep 8, 2009, 10:03:54 PM9/8/09
to Programming Nu

> I'm now using the latest SDK.

That is, I have the latest SDK installed, but I'm still targeting
2.0. Targeting other versions doesn't seem to make any difference.

Tim Burks

unread,
Sep 8, 2009, 11:14:48 PM9/8/09
to program...@googlegroups.com
It appears that the problem is due to an API change.

In the example, we use a UIImageView as the "content view" for the app
and add the buttons and textfields as subviews of this UIImageView. In
retrospect, I'm surprised that this ever worked; at the time I was
following an Objective-C example line-by-line. Here is the old
applicationDidFinishLaunching: method:

==============================================================

(- (void)applicationDidFinishLaunching:(id)application is
;; Set up the window and content view
(set screenRect ((UIScreen mainScreen) bounds))
(set @window ((UIWindow alloc) initWithFrame:screenRect))

;; Add the image as the background view
(set anImageView ((UIImageView alloc) initWithFrame:((UIScreen
mainScreen) applicationFrame)))
(anImageView setImage:(UIImage imageNamed:"Background.png"))
(set @contentView anImageView)

(@window addSubview:@contentView)
(self addControlsToContentView:@contentView)

;; Show the window
(@window makeKeyAndVisible)))

==============================================================

In the updated method (below), I create a separate content view as a
UIView and add the button and text field to it. Now those two UI
elements respond to touches.

==============================================================

(- (void)applicationDidFinishLaunching:(id)application is
;; Set up the window and content view
(set screenRect ((UIScreen mainScreen) bounds))
(set @window ((UIWindow alloc) initWithFrame:screenRect))

;; Add the image as the background view
(set anImageView ((UIImageView alloc) initWithFrame:((UIScreen
mainScreen) applicationFrame)))
(anImageView setImage:(UIImage imageNamed:"Background.png"))
(@window addSubview:anImageView)

(set @contentView ((UIView alloc) initWithFrame:((UIScreen
mainScreen) applicationFrame)))
(@window addSubview:@contentView)
(self addControlsToContentView:@contentView)

;; Show the window
(@window makeKeyAndVisible)))

==============================================================

I have an updated Xcode project that builds and runs on the iPhone
(but not the simulator). I'll pull that into a tar file and post it
soon.

Tim



On Tue, Sep 8, 2009 at 7:12 PM, Tim Burks<timb...@gmail.com> wrote:
>
> OK, I'll build it and look into the problem.

stuntmouse

unread,
Sep 8, 2009, 11:17:22 PM9/8/09
to Programming Nu


SOLVED.

The issue must be with adding the button and textfield to a
UIImageView. Using a plain UIView instead works (on simulator and
phone).

Thanks!

stuntmouse

unread,
Sep 9, 2009, 12:00:35 AM9/9/09
to Programming Nu

UPDATE

Looks like we reached the same conclusion :)

However, I'm getting a crash when running the app on the phone without
the debugger attached.

I've tried syncing, but I'm not getting a crash report.

Does yours work when started without the debugger?

stephen white

unread,
Sep 9, 2009, 1:22:13 PM9/9/09
to program...@googlegroups.com
On 09/09/2009, at 12:44 PM, Tim Burks wrote:
> retrospect, I'm surprised that this ever worked; at the time I was
> following an Objective-C example line-by-line. Here is the old


If the Objective-C version worked, why would it need to be different
in Nu?

--
st...@adam.com.au


Tim Burks

unread,
Sep 9, 2009, 1:24:49 PM9/9/09
to program...@googlegroups.com
It wouldn't -- the converted example worked at the time I made it, but
that was 18 months ago.
Reply all
Reply to author
Forward
0 new messages