I´m learning IOS/Objective-C and I have this users input Quizz project; at the moment I can show all questions and answers (with buttons and labels). But as for the next step - user inputs the answer and gets Right or Wrong - something is missing; I cant seem to match the user´s input to the index. If I write something, the output is always "Wrong". The code:
#import "QuizzViewController.h"
#import "Question.h"
#interface QuizzViewController ()
#property (weak, nonatomic) IBOutlet UILabel *questionLabel;
#property (weak, nonatomic) IBOutlet UILabel *answerLabel;
#property NSArray *questions;
#property NSUInteger index;
#property (weak, nonatomic) IBOutlet UILabel *answerValidation;
#property (weak, nonatomic) IBOutlet UITextField *inputAction;
#property (weak, nonatomic) IBOutlet UIButton *answerButton;
#end
#implementation QuizzViewController
- (void)viewDidLoad {
[super viewDidLoad];
_questions = #[
[Question question:#"Best surfer in the World?" answer:#"Kelly Slater"],
[Question question:#"Capital of England?" answer:#"London"],
[Question question:#"Capital of Argentina?" answer:#"Buenos Aires"]
];
_index = -1;
[self nextQuestionAction];
}
- (IBAction)answerAction:(UIButton *)sender {
Question *question = [_questions objectAtIndex:_index];
NSString *correct=#"Correct";
NSString *wrong=#"Wrong";
_inputAction.text=question.answer;
if (question.answer==_inputAction.text){
_answerValidation.text=correct;
}else{
_answerValidation.text=wrong;
}
}
/*- (IBAction)inputAction:(UITextField *)sender {
Question *question = [_questions objectAtIndex:_index];
NSString *correct=#"Correct";
NSString *wrong=#"Wrong";
if (question.answer==_inputAction.text){
_answerValidation.text=correct;
}else{
_answerValidation.text=wrong;
}
}*/
- (IBAction)nextQuestionAction {
_index = (_index + 1) % _questions.count;
Question *question = [_questions objectAtIndex:_index];
_questionLabel.text = question.question;
_answerLabel.text = #"...";
}
- (IBAction)showAnswerAction {
Question *question = [_questions objectAtIndex:_index];
_answerLabel.text = question.answer;
}
#end
I guess I need to point the index, but I've tried in different ways, and it's not working...Thanks for the help
The answer, with the help of Larme:
- (IBAction)answerAction:(UIButton *)sender {
Question *question = [_questions objectAtIndex:_index];
NSString *correct=#"Correct";
NSString *wrong=#"Wrong";
_inputAction.text=question.answer;
if ([question.answer isEqualToString:_inputAction.text]){
_answerValidation.text=correct;
}else{
_answerValidation.text=wrong;
}
}
The comparinson has to be made with the "isEqualToString" method
Related
i have a group of textfields and Segmented Control.
i have to get input from a service to all the UIElements, getting correct input for textfields but not the SegmentedControl. Below is my code and ScreenShot attached Please check the image for issue with SegmentedControl TIA
#interface EditBasicProfileViewController ()
#property(nonatomic,strong)NSMutableDictionary *userDict;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) IBOutlet UIView *basicProfileView;
#property (strong, nonatomic) IBOutlet UITextField *txtCellPhone;
#property (strong, nonatomic) IBOutlet UITextField *txtWorkPhone;
#property (strong, nonatomic) IBOutlet UITextField *txtAdress;
#property (strong, nonatomic) IBOutlet UITextField *txtCountry;
#property (strong, nonatomic) IBOutlet UITextField *txtState;
#property (strong, nonatomic) IBOutlet UITextField *txtCity;
#property (strong, nonatomic) IBOutlet UITextField *txtMotherTongue;
#property (strong, nonatomic) IBOutlet UITextField *txtZipcode;
#property (strong, nonatomic) IBOutlet UISegmentedControl *genderSegment;
#property (strong, nonatomic) IBOutlet UISegmentedControl *seekingGenderSegment;
- (IBAction)genderSegmentValueChanged:(id)sender;
- (IBAction)seekingGenderSegmentValueChanged:(id)sender;
- (IBAction)btnCountry:(id)sender;
- (IBAction)btnState:(id)sender;
- (IBAction)btnCity:(id)sender;
- (IBAction)btnMotherTongue:(id)sender;
- (IBAction)btnUpdateClicked:(id)sender;
#property (strong, nonatomic) IBOutlet UIButton *updateButton;
#end
#implementation EditBasicProfileViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[super viewDidLoad];
[self.scrollView addSubview:_basicProfileView];
[_scrollView
setContentSize:self.basicProfileView.frame.size];
gender=#"0";
seekingGender=#"1";
_basicProfileView.backgroundColor=[UIColor clearColor];
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[dict setObject:UserId forKey:#"userId"];
[self ProfileDisplayService:dict];
}
- (IBAction)genderSegmentValueChanged:(id)sender {
if (_genderSegment.selectedSegmentIndex==0)
{
gender=#"0";
}
else
{
gender=#"1";
}
}
- (IBAction)seekingGenderSegmentValueChanged:(id)sender {
if (_seekingGenderSegment.selectedSegmentIndex==0)
{
seekingGender=#"0";
}
else
{
seekingGender=#"1";
}
}
-(void)setupValues
{
gender =[_userDict objectForKey:#"UserGender"];
seekingGender = [_userDict objectForKey:#"SeekingGender"];
_txtCellPhone.text=[_userDict objectForKey:#"UserPhone"];
_txtWorkPhone.text=[_userDict objectForKey:#"UserWorkPhone"];
_txtAdress.text=[_userDict objectForKey:#"UserAddress"];
_txtCountry.text=[_userDict objectForKey:#"UserCountryName"];
_txtState.text=[_userDict objectForKey:#"UserStateName"];
_txtCity.text=[_userDict objectForKey:#"UserCityName"];
_txtMotherTongue.text=[_userDict objectForKey:#"motherTounge"];
_txtZipcode.text=[_userDict objectForKey:#"UserZipCode"];
}
- (IBAction)btnUpdateClicked:(id)sender {
reqType=#"BasicDtls";
[self callEditProfileService:dict];
}
-(void)ProfileDisplayService:(NSMutableDictionary *)dict
{
NSString * post = [[NSString alloc]initWithFormat:#"reqType=BasicDtls&userId=%#",UserId];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"Some Url"]];
RBConnect = [[RBConnection alloc]init];
RBConnect.delegate = self;
[RBConnect postRequestForUrl:url postBody:post];
}
#pragma mark - MRConnection Delegate Methods
- (void)jsonData:(NSDictionary *)jsonDict
{
[SVProgressHUD dismiss];
NSMutableArray *jsonArr;
jsonArr=[jsonDict objectForKey:#"DataTable"];
if (![jsonArr isEqual:[NSNull null]]) {
if ([[jsonArr objectAtIndex:0] objectForKey:#"ABSDetails"]) {
NSMutableDictionary *userDict=[[jsonArr objectAtIndex:0] objectForKey:#"ABSUserDtls"];
gender = [userDict objectForKey:#"UserGender"];
seekingGender = [userDict objectForKey:#"SeekingGender"];
_txtCellPhone.text=[userDict objectForKey:#"UserPhone"];
_txtWorkPhone.text=[userDict objectForKey:#"UserWorkPhone"];
_txtAdress.text=[userDict objectForKey:#"UserAddress"];
_txtCountry.text=[userDict objectForKey:#"UserCountryName"];
_txtState.text=[userDict objectForKey:#"UserStateName"];
_txtCity.text=[userDict objectForKey:#"UserCityName"];
_txtMotherTongue.text=[userDict objectForKey:#"motherTounge"];
_txtZipcode.text=[userDict objectForKey:#"UserZipCode"];
}
}
}
I have been following online tutorials over at raywenderlich.com, and came upon a little road block. In a tutorial (Quote Quiz), I seem to have done something wrong because the strings, extracted from the Quote.plist, is simply not displaying on the question and answers labels.
Here is my view controller.h:
#import <UIKit/UIKit.h>
#class Quiz;
#interface ViewController : UIViewController
#property (nonatomic, assign) NSInteger quizIndex;
#property (nonatomic, strong) Quiz* quiz;
#property (nonatomic, weak) IBOutlet UILabel* questionLabel;
#property (nonatomic, weak) IBOutlet UILabel* answer1Label;
#property (nonatomic, weak) IBOutlet UILabel* answer2Label;
#property (nonatomic, weak) IBOutlet UILabel* answer3Label;
#property (nonatomic, weak) IBOutlet UIButton* answer1Button;
#property (nonatomic, weak) IBOutlet UIButton* answer2Button;
#property (nonatomic, weak) IBOutlet UIButton* answer3Button;
#property (nonatomic, weak) IBOutlet UIImageView* movie1;
#property (nonatomic, weak) IBOutlet UIImageView* movie2;
#property (nonatomic, weak) IBOutlet UIImageView* movie3;
#property (nonatomic, weak) IBOutlet UILabel* statusLabel;
#property (nonatomic, weak) IBOutlet UIButton* startButton;
#property (nonatomic, weak) IBOutlet UIButton* infoButton;
#end
.m
#import "ViewController.h"
#import "Quiz.h"
#interface ViewController ()
#property (nonatomic, assign) NSInteger answer;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.quizIndex = 999;
self.quiz = [[Quiz alloc] initWithQuiz:#"Quotes"];
self.questionLabel.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
[self nextQuizItem];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) nextQuizItem {
if(self.quizIndex == 999){
self.quizIndex = 0;
self.statusLabel.text = #"";
}else if((self.quiz.quizCount-1) > self.quizIndex) {
self.quizIndex++;
}else{
self.quizIndex = 0;
self.statusLabel.text = #"";
}
if(self.quiz.quizCount >= (self.quizIndex+1)){
self.questionLabel.text = self.quiz.quote;
self.answer1Label.text = self.quiz.ans1;
self.answer2Label.text = self.quiz.ans2;
self.answer3Label.text = self.quiz.ans3;
}else{
self.quizIndex = 0;
[self quizDone];
}
self.answer1Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
self.answer2Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
self.answer3Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
self.answer1Button.hidden = NO;
self.answer2Button.hidden = NO;
self.answer3Button.hidden = NO;
}
-(void) quizDone {
}
#end
And my Quiz.h:
#import <Foundation/Foundation.h>
#interface Quiz : NSObject
#property (nonatomic, strong) NSMutableArray* movieArray;
#property (nonatomic, assign) NSInteger correctCount;
#property (nonatomic, assign) NSInteger incorrectCount;
#property (nonatomic, assign) NSInteger quizCount;
#property (nonatomic, readonly, strong) NSString* quote;
#property (nonatomic, readonly, strong) NSString* ans1;
#property (nonatomic, readonly, strong) NSString* ans2;
#property (nonatomic, readonly, strong) NSString* ans3;
-(id)initWithQuiz:(NSString*)plistName;
-(void)nextQuestion:(NSUInteger)idx;
-(BOOL)checkQuestion:(NSUInteger)question forAnswer:(NSUInteger)answer;
#end
and Quiz.m:
#import "Quiz.h"
#interface Quiz()
#property (nonatomic, strong) NSString* quote;
#property (nonatomic, strong) NSString* ans1;
#property (nonatomic, strong) NSString* ans2;
#property (nonatomic, strong) NSString* ans3;
#end
#implementation Quiz
-(id)initWithQuiz:(NSString *)plistName {
if((self=[super init])) {
NSString* plistCatPath = [[NSBundle mainBundle] pathForResource:plistName ofType:#"plist"];
self.movieArray = [NSMutableArray arrayWithContentsOfFile:plistCatPath];
self.quizCount = [self.movieArray count];
}
return self;
}
-(void)nextQuestion:(NSUInteger)idx {
self.quote = [NSString stringWithFormat:#"%#", self.movieArray[idx][#"quote"]];
self.ans1 = self.movieArray[idx][#"ans1"];
self.ans2 = self.movieArray[idx][#"ans2"];
self.ans3 = self.movieArray[idx][#"ans3"];
if(idx == 0){
self.correctCount = 0;
self.incorrectCount = 0;
}
}
-(BOOL)checkQuestion:(NSUInteger)question forAnswer:(NSUInteger)answer {
NSString* ans = [NSString stringWithFormat:#"%#", self.movieArray[question][#"answer"]];
if([ans intValue] == answer) {
self.correctCount++;
return YES;
}else{
self.incorrectCount++;
return NO;
}
}
#end
I am using the latest Xcode 6, the outlets are connected, and the plist file I am using has the name "Quotes.plist".
Any help or suggestion would be greatly appreciated.
Thank you.
You are not getting the next quiz question before displaying it.
Add the following to the second if statement of nextQuizItem in ViewController.m:
[self.quiz nextQuestion:self.quizIndex];
so that it looks like this
if(self.quiz.quizCount >= (self.quizIndex+1)){
[self.quiz nextQuestion:self.quizIndex]; // <-- ADD THIS
self.questionLabel.text = self.quiz.quote;
self.answer1Label.text = self.quiz.ans1;
self.answer2Label.text = self.quiz.ans2;
self.answer3Label.text = self.quiz.ans3;
}else{
self.quizIndex = 0;
[self quizDone];
}
I'm populating an object's fields from Labels, when displaying in Log the label is the correct value, but the object's field is null. I'm coming over from an Android/ Java background and this is just awkward.
Any help would be great.
To be clear, the "soil type field" log shows "example"while the "soil type" log shows (null)
- (IBAction)saveButton:(id)sender {
Soil *thisSoil = self.thisSoil;
thisSoil.soilType = self.soilNameField.text;
NSLog(#"soil type field %#", self.soilNameField.text);
NSLog(#"soil type: %#", thisSoil.soilType);
thisSoil.frictionAngle = [self.frictionAngleValue.text integerValue];
if ([self.soilUnitsSwitch isOn] ) {
thisSoil.cohesion = [self.cohesionValue.text doubleValue];
thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
}else{
thisSoil.cohesion = [self.cohesionValue.text doubleValue];
thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
}
[self.delegate SoilCreatorViewController:self didFinishItem:thisSoil];
[self.navigationController popViewControllerAnimated:YES];
}
The entire controller .m file
#import "SoilCreatorViewController.h"
#define IMPERIAL_TO_METRIC 0.3048
#define KG_TO_LBS 2.2
#interface SoilCreatorViewController ()
#end
#implementation SoilCreatorViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)soilQuestions:(id)sender {
[self popupmaker :#"Friction Angle" : #"Phi is the angle of internal friction for soil, which governs soil strength and resistance. This value should be attained from competent field testing and the judgment of a licensed engineer."];
[self popupmaker :#"Soil Cohesion": #"Cohesion defines the non-stress dependent shear strength of soil and should be used with caution. Typically,cohesion occurs in stiff, over-consolidated clays or cemented native soils. Cohesion should be neglected if the designer is unsure of its presence."];
}
- (IBAction)SwitchDidChange:(id)sender {
if ([sender isOn]) {
self.cohesionUnits.text = #"Ft";
self.unitWeightUnits.text= #"M";
}else{
self.cohesionUnits.text = #"M";
self.unitWeightUnits.text = #"M";
}
}
- (IBAction)unitWtDidChange:(id)sender {
self.unitWeightValue.text = [NSString stringWithFormat:#"%.1f", (double)self.unitWeightStepper.value];
}
- (IBAction)frictionAngleDidChange:(id)sender {
self.frictionAngleValue.text = [NSString stringWithFormat:#"%d", (int)self.frictionAngleStepper.value];
}
- (IBAction)cohesionDidChange:(id)sender {
self.cohesionValue.text = [NSString stringWithFormat:#"%.1f", (double)self.cohesionStepper.value];
}
- (IBAction)textFieldDismiss:(id)sender {
[[self view] endEditing:YES];
}
- (IBAction)UnitSwitch:(id)sender {
if ([sender isOn]) {
self.unitWeightUnits.text = #"LBS/cubic Ft.";
self.cohesionUnits.text = #"imp";
}else{
self.unitWeightUnits.text = #"KG/m3";
self.cohesionUnits.text = #"met";
}
}
- (IBAction)cancelButton:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)saveButton:(id)sender {
Soil *thisSoil = self.thisSoil;
thisSoil.soilType = self.soilNameField.text;
NSLog(#"soil type field %#", self.soilNameField.text);
NSLog(#"soil type: %#", thisSoil.soilType);
thisSoil.frictionAngle = [self.frictionAngleValue.text integerValue];
if ([self.soilUnitsSwitch isOn] ) {
thisSoil.cohesion = [self.cohesionValue.text doubleValue];
thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
}else{
thisSoil.cohesion = [self.cohesionValue.text doubleValue];
thisSoil.unitWeight = [self.unitWeightValue.text doubleValue];
}
[self.delegate SoilCreatorViewController:self didFinishItem:thisSoil];
[self.navigationController popViewControllerAnimated:YES];
}
-(void)popupmaker:(NSString *)title :(NSString *)message{
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil
];
[alert show];
}
#end
The .h file
#import "Soil.h"
#class SoilCreatorViewController;
#protocol SoilCreatorViewDelegate <NSObject>
-(void)SoilCreatorViewController:(SoilCreatorViewController *)controller didFinishItem:(Soil *)item;
#property (nonatomic, weak) id <SoilCreatorViewDelegate> delegate;
#end
#import <UIKit/UIKit.h>
#import "CalculationDetailViewController.h"
#interface SoilCreatorViewController : UIViewController
#property (nonatomic,weak) id<SoilCreatorViewDelegate> delegate;
#property (weak, nonatomic) IBOutlet UITextField *soilNameField;
#property (weak, nonatomic) IBOutlet UISwitch *soilUnitsSwitch;
#property (nonatomic,strong) Soil *thisSoil;
#property (weak, nonatomic) IBOutlet UIStepper *frictionAngleStepper;
#property (weak, nonatomic) IBOutlet UIStepper *unitWeightStepper;
#property (weak, nonatomic) IBOutlet UIStepper *cohesionStepper;
#property (weak, nonatomic) IBOutlet UILabel *unitWeightValue;
#property (weak, nonatomic) IBOutlet UILabel *frictionAngleValue;
#property (weak, nonatomic) IBOutlet UILabel *cohesionValue;
#property (weak, nonatomic) IBOutlet UILabel *unitWeightUnits;
#property (weak, nonatomic) IBOutlet UILabel *cohesionUnits;
- (IBAction)soilQuestions:(id)sender;
- (IBAction)SwitchDidChange:(id)sender;
- (IBAction)unitWtDidChange:(id)sender;
- (IBAction)frictionAngleDidChange:(id)sender;
- (IBAction)cohesionDidChange:(id)sender;
- (IBAction)textFieldDismiss:(id)sender;
- (IBAction)cancelButton:(id)sender;
- (IBAction)saveButton:(id)sender;
-(void)popupmaker:(NSString *)title :(NSString *)message;
#end
I don't see any code that sets up thisSoil. At some point in your code, you need to write something like
self.thisSoil = [[Soil alloc] init];
or self.thisSoil will stay nil forever.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager startRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager stopRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tagname.text = [self.TagDetail objectForKey:#"Name"];
self.title = [self.TagDetail objectForKey:#"Name"];
NSString *proximity = #"near";
if ([beacon.proximity == CLProximityNear:]) {
NSLog(#"Show near");
[self.near setHidden:(NO)];
[self.far setHidden:(YES)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityFar]) {
NSLog(#"Show");
[self.near setHidden:(YES)];
[self.far setHidden:(NO)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityImmediate]) {
NSLog(#"Show");
[self.near setHidden: (YES)];
[self.far setHidden: (YES)];
[self.immediate setHidden: (NO)];
}
Heres the .h file
#interface TagDetailViewController : UIViewController
#property (nonatomic, strong) PFObject* TagDetail;
#property (strong, nonatomic)IBOutlet UILabel *tagname;
#property (nonatomic, strong)IBOutlet UIImageView *immediate;
#property (nonatomic, strong)IBOutlet UIImageView *near;
#property (nonatomic, strong)IBOutlet UIImageView *far;
#property (nonatomic, strong)IBOutlet UIButton *showOnMap;
#property CLLocationManager *locationManager;
#property CLBeaconRegion *rangedRegion;
#property NSUUID *artemisUUID;
#property CLBeaconMajorValue *major;
#property CLBeaconMinorValue *minor;
#property CLBeacon *proximity;
#end
Its telling me that the variable beacon is not identified, but doing so in the header file as *beacon doesn't remove any errors. What am I doing wrong? Im really new to this language so that is a large part of why Im running into errors, but I cant figure this one out.
You don't have a variable named beacon, you have a CLBeacon object named proximity.
I am new to iPhone App development, below is ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self updateMyView];
}
- (IBAction)clickButtonResult:(id)sender
{
enteredText = [textField text]; // Or textField.text
NSLog(#"Number 1 : %i", number_1);
NSLog(#"Number 2 : %i", number_2);
NSLog(#"Entered Text is %#", enteredText);
int NUM_RESULT = number_1 + number_2;
verify_result = [NSString stringWithFormat:#"%i", NUM_RESULT];
NSLog(#"Verify Result : %#", verify_result);
NSString *final_result = [NSString stringWithFormat:#"%d", [enteredText isEqualToString:verify_result]];
int final_int_result = [final_result integerValue];
if (final_int_result) {
//result_label.text = #"Correct";
NSLog(#"Correct");
[self updateMyView];
} else {
//result_label.text = #"Wrong";
NSLog(#"Wrong");
}
}
- (int)getRandomNumberBetween:(int)min maxNumber:(int)max
{
return min + arc4random() % (max - min + 1);
}
- (void) updateMyView
{
number_1 = [self getRandomNumberBetween:10 maxNumber:99];
number_2 = [self getRandomNumberBetween:10 maxNumber:99];
num_1.text = [NSString stringWithFormat:#"%i", number_1];
num_2.text = [NSString stringWithFormat:#"%i", number_2];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UILabel *num_1;
IBOutlet UILabel *num_2;
IBOutlet UILabel *result_label;
IBOutlet UITextField *textField;
int number_1;
int number_2;
NSString *verify_result;
NSString *enteredText;
BOOL display_result;
}
- (IBAction)clickButtonResult:(id)sender;
#end
After entering the correct result the UIView should be updated with updateMyView function but it is not happening.
Can anyone help here??
First of all, start using Properties.
ViewController.h
#interface ViewController : UIViewController
#property (nonatomic, weak) IBOutlet UILabel *num_1;
#property (nonatomic, weak) IBOutlet UILabel *num_2;
#property (nonatomic, weak) IBOutlet UILabel *resultLabel;
#property (nonatomic, weak) IBOutlet UITextField *textField;
#property (nonatomic) NSInteger number_1;
#property (nonatomic) NSInteger number_2;
#property (nonatomic, strong) NSString *verifyResult;
#property (nonatomic, strong) NSString *enteredText;
#property (nonatomic) BOOL displayResult;
- (IBAction)clickButtonResult:(id)sender;
#end
In ViewController.m code use self.{name of property}, for example self.textField for the textField property.
Now, go to Interface builder and connect the IBOutlet properties to the right objects. (click with right button on File's Owner)
Try changing num_1.text in viewDidLoad to make sure you have access to that label from your UIViewController.
So in viewDidLoad, just put something like
num1.text = #"Updated from viewDidLoad"
Make sure that you have connected num_1 and num_2 with the UILabels properly. It seems that you have not connected these.
Just move [self updateMyView]; outside the if statements in clickButtonResult: function
then it will update the view when click the button.
if (final_int_result) {
//result_label.text = #"Correct";
NSLog(#"Correct");
} else {
//result_label.text = #"Wrong";
NSLog(#"Wrong");
}
[self updateMyView];