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 04-02-2010, 11:16 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 5
rabbigarfinkel1 is on a distinguished road
Default Why is my IBAction begin triggered twice?

Hello,

I am trying to write a simple program that asks users yes/no questions and, based on those answers, tells them where they stand on the political spectrum.

I have a variable in my code called "questionnumber." My thought was that every time the user clicked the "nextbutton" in my IB interface, I would increase the "questionnumber" variable by 1 and thus present a new question.

This works for questions 1 and 2. But then it starts skipping every other question. Can someone tell me why? I'm stumped! The code appears below: (My IB interface buttons are keyed for "touch up inside" in case that makes a difference.)

#import "MainView.h"
#import <Foundation/Foundation.h>

@implementation MainView
@synthesize Question;
@synthesize mispar;


int conservative = 0;
int liberal = 0;
int questionnumber = 0;

- (IBAction)agreebuttonid)sender {

++liberal;

}

- (IBAction)disagreebuttonid)sender {

++conservative;

}

- (IBAction)nextbuttonid)sender {

++questionnumber;

switch (questionnumber) {

case 1:

Question.text = @"text of question 1";
break;

case 2:

Question.text = @"test of question 2";
break;


case 3:

Question.text = @"text of question 3";
break;

case 4:

Question.text = @"text of question 4";
break;


case 5:
Question.text = @"text of quesiton 5";
break;

case 6:
Question.text = @"text of question 6";
break;

case 7:
Question.text = @"text of question 7";
break;

case 8:
Question.text = @"text of question 8.";
break;

case 9:
Question.text = @"text of question 9";
break;

default:
break;
}
}

@end
rabbigarfinkel1 is offline   Reply With Quote
Old 04-02-2010, 03:30 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: London/Peterborough
Posts: 562
QuantumDoja is on a distinguished road
Default

Check you haven't wired up that action twice to the button in IB. It may be being called on touch down and release.
QuantumDoja is offline   Reply With Quote
Old 06-19-2010, 10:16 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
apricoti is on a distinguished road
Default only "touch up inside" is used and only once

The same thing is happening to me.

I confirmed in IB that the only handled event for the button is "touch up inside" and that there is only one received action in my "file's owner" for the method that is being called twice.

For me, the double calling is happening even the first time I touch the button.
apricoti is offline   Reply With Quote
Old 06-19-2010, 11:17 AM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Either the method is getting called twice, or something else is incrementing your questionnumber.

I'd add some NSLogs inside your next button action.

Code:
NSLog(@" questionnumber before: %d", questionnumber);
questionnumber++;
NSLog(@" questionnumber after: %d", questionnumber);
You'll immediately see if nextbutton is being called twice, or whether someone else is changing questionnumber.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
ibaction, trigger twice, variable

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: 311
6 members and 305 guests
chemistry, heshiming, iAppDeveloper, jbro, kapps11, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,872
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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