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 10-18-2010, 02:20 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 38
loddy1234 is on a distinguished road
Exclamation What's Wrong?

The idea of my app is the user is asked a question via a label, they then type the answer into a text box and presses a button. if they get the answer wrong three times, an "i give up" button becomes active and they can click it to show the answer

here is my .h file
Code:
#import <UIKit/UIKit.h>
#import "questionOne.h"

@interface questionOne : UIViewController {
	
	IBOutlet UITextField *answer;
	IBOutlet UIButton *giveUp;
	IBOutlet UIViewController *secondQuestion;

}

-(IBAction)nextQuestion: (id) sender;
-(IBAction)hideKeyboard: (id) sender;
-(IBAction)showAnswer: (id) sender;
@property (nonatomic, retain) IBOutlet UITextField *answer;
@property (nonatomic, retain) IBOutlet UIButton *giveUp;
@end

and here is my .m file

Code:
#import "questionOne.h"


@implementation questionOne;
@synthesize answer;
@synthesize giveUp;

NSInteger attempts = 0;


-(IBAction)showAnswer:(id) sender{
	
		answer.text = @"yes";
}



-(IBAction)nextQuestion:(id) sender{
	
	if (answer.text = @"yes"){
		[self presentModalViewController:secondQuestion animated:YES];
	
	}
	
	else {
		attempts ++;
	}


	if (attempts > 2) {
		
		giveUp.enabled = YES;
	}

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}


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


@end
showAnswer is linked to a button
nextQuestion is linked to a button
secondQuestion is linked to a view controller

When the nextQuestion button is pressed, the text box is set to yes and the next view is shown. Why does it do this???
Any help greatly appreciated.
Thanks in advance
loddy1234 is offline   Reply With Quote
Old 10-18-2010, 03:10 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

The only possibility that I see is that you've got your nextQuestion button connected to BOTH showAnswer AND nextQuestion. Did you, by any chance, first connect the button accidentally to showAnswer and then try to correct it by connecting the button to nextQuestion? If so, you might have thought the second connection erases the first one, but instead, it just told the button to call BOTH methods.

You're going to want to go to the connections tab of the nextQuestion button, and under "events", find where it says something like "Multiple", click the little "x" button there, and reconnect it to only the nextQuestion method.

Logically (assuming IB was set up correctly), your code works, so if this doesn't do it, it has to be something with IB (or otherwise something outside the scope of this code). In that case try deleting both buttons and recreating and reconnecting them from scratch.
__________________
HEY! Was this post helpful?
If so, it would be MUCH appreciated if you'd just click on one of these apps:



MyD
Take 1 minute to set up your MyD and you'll always be able to prove you own your device!

Membrik
Test your memory by sliding tiles to match chains of increasing difficulty.

©2011 Dardom Productions | Like us on Facebook!
SoulRed12 is offline   Reply With Quote
Old 10-18-2010, 03:51 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 38
loddy1234 is on a distinguished road
Unhappy

Quote:
Originally Posted by SoulRed12 View Post
The only possibility that I see is that you've got your nextQuestion button connected to BOTH showAnswer AND nextQuestion. Did you, by any chance, first connect the button accidentally to showAnswer and then try to correct it by connecting the button to nextQuestion? If so, you might have thought the second connection erases the first one, but instead, it just told the button to call BOTH methods.

You're going to want to go to the connections tab of the nextQuestion button, and under "events", find where it says something like "Multiple", click the little "x" button there, and reconnect it to only the nextQuestion method.

Logically (assuming IB was set up correctly), your code works, so if this doesn't do it, it has to be something with IB (or otherwise something outside the scope of this code). In that case try deleting both buttons and recreating and reconnecting them from scratch.
The enter button was only connected to nextQuestion but i deleted both buttons and re-linked them but it still doesn't work
loddy1234 is offline   Reply With Quote
Old 10-18-2010, 04:11 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 651
kapps11 is on a distinguished road
Default

No, the problem is in your logic statements.

you used:

if (answer.text = @"yes")

first off, == is the logic statement operand, not =. But saying =, you are actually setting the text to @"yes" and that is why that happens. However, to compare two nsstrings, you need to use the isEqualToString method. So your new if statemtent would look like:

if ([answer.text isEqualTo:@"yes") {
//do stuff
}
kapps11 is offline   Reply With Quote
Old 10-18-2010, 08:13 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

Quote:
Originally Posted by kapps11 View Post
No, the problem is in your logic statements.

you used:

if (answer.text = @"yes")

first off, == is the logic statement operand, not =. But saying =, you are actually setting the text to @"yes" and that is why that happens. However, to compare two nsstrings, you need to use the isEqualToString method. So your new if statemtent would look like:

if ([answer.text isEqualTo:@"yes") {
//do stuff
}
Ah! I can't believe I missed that! Sorry OP >_<
__________________
HEY! Was this post helpful?
If so, it would be MUCH appreciated if you'd just click on one of these apps:



MyD
Take 1 minute to set up your MyD and you'll always be able to prove you own your device!

Membrik
Test your memory by sliding tiles to match chains of increasing difficulty.

©2011 Dardom Productions | Like us on Facebook!
SoulRed12 is offline   Reply With Quote
Old 10-18-2010, 08:30 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 651
kapps11 is on a distinguished road
Default

oops sorry! actually its isEqualToString:

my bad hah
kapps11 is offline   Reply With Quote
Reply

Bookmarks

Tags
box, button, field, question, text

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: 336
7 members and 329 guests
Desert Diva, dre, hain, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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