Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-28-2011, 03:35 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
gs1982 is on a distinguished road
Default Sender

Hi all,

I'm brand new to xcode and need a little help with something very basic.

I have a xib file with two buttons and a label. The label is connected to an IBOutlet and both buttons to the same IBAction. The IBAction simply changes the label to "Test". So whichever button I press, the label changes to "Test". So far so good, this works fine and the code is as follows:

ButtonsAppDelegate.h

Code:
#import <UIKit/UIKit.h>

@interface ButtonsAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	IBOutlet UILabel *label1;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

- (IBAction)buttonPress;

@end

ButtonsAppDelegate.m

Code:
#import "ButtonsAppDelegate.h"

@implementation ButtonsAppDelegate

@synthesize window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

- (IBAction)buttonPress;
{
	label1.text = @"Test";
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

Next I want to work out which button triggered the IBAction, so I can change the label text to something different depending on which button is pressed (I'll probably just change the label text to the specific button's title).

My understanding is that the first thing I have to do is to get the "sender" of the IBAction. However, adding this code causes the app to no longer work. Clicking on a button seems to terminate the app with an uncaught exception.

The code is as follows. I appreciate that I'm not actually trying to use the sender to do what I described above - that was going to be the next step. For now I just want to understand why adding the small amount of code that I have has broken the method.

ButtonsAppDelegate.h

Code:
#import <UIKit/UIKit.h>

@interface ButtonsAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
	IBOutlet UILabel *label1;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

- (IBAction)buttonPress: (id)sender;

@end

ButtonsAppDelegate.m

Code:
#import "ButtonsAppDelegate.h"

@implementation ButtonsAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

- (IBAction)buttonPress: (id)sender{
	label1.text = @"Test";
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

Any help would be much appreciated.

Many thanks,
Gary
gs1982 is offline   Reply With Quote
Old 08-28-2011, 03:40 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

I'm going to guess you didn't remove the connection with the old method and attach a new connection with the new method.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 08-28-2011, 04:11 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 2
gs1982 is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
I'm going to guess you didn't remove the connection with the old method and attach a new connection with the new method.

You little beauty! Thanks a lot. I had assumed that because I wasn't changing the method name there was no need for that.
gs1982 is offline   Reply With Quote
Old 08-28-2011, 06:20 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by gs1982 View Post
You little beauty! Thanks a lot. I had assumed that because I wasn't changing the method name there was no need for that.
A method with a different number of parameters is a different method.


Code:
@selector(foo)
and

Code:
@selector(foo:)
are two different method signatures.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
ibaction sender id button

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 389
5 members and 384 guests
JackReidy, jeroenkeij, Sami Gh, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0