我是新iPhone應用程序的開發,下面是ViewController.m的UIView在iPhone應用程序不更新
#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
和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
輸入正確的結果了UIView應該更新後與updateMyView函數,但它沒有發生。
任何人都可以在這裏幫助?
有你在clickButtonResult方法設置一個斷點,並通過單步,以確保一)它被稱爲和b)它是做你期待什麼?順便說一句,使用'[textField.text intergerValue]'可能更簡單,而不是將結果轉換爲字符串並比較字符串。 – Paulw11
看看是否您更新視圖的功能和clickresult通過使用斷點 – iOSDeveloper
什麼斷點,我沒有得到理解這裏叫什麼? – Bangaram