我正在教自己通過斯坦福大學CS193P課程的iOS 5編程,我剛剛開始並且正在進行第一個項目。我想使用NSLog()將值回顯給控制檯,並且我從控制器中發送到控制檯的所有日誌都顯示出來,但是從模型類發送的任何NSLog消息都不會。難道我做錯了什麼?Xcode-NSLog()沒有從模型類登錄到控制檯?
從我CalculatorViewController.m
文件:
- (IBAction)enterPressed
{
//The Following NSLog() works.
NSLog(@"Adding number %g to operandStack", [self.display.text doubleValue]);
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMiddleOfEnteringANumber = NO;
}
從我CalculatorBrain.m
文件:
-(void)pushOperand:(double)operand
{
//The Following NSLog() doesn't show up in the console
NSLog(@"Received number %@ for operandStack", operand);
NSNumber *operandObject = [NSNumber numberWithDouble:operand];
[self.operandStack addObject:operandObject];
}
代碼工作不正常或者,一切編譯和運行得很好,沒有任何警告或錯誤,但模型中的方法沒有返回預期的對象,它們是(無),所以我覺得控制器與模型交互的方式是錯誤的?
這是我如何BTW實例化CalculatorBrain型號:
#import "CalculatorViewController.h"
#import "CalculatorBrain.h"
@interface CalculatorViewController()
@property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
@property (nonatomic, strong) CalculatorBrain *brain;
@end
@implementation CalculatorViewController
@synthesize display = _display;
@synthesize userIsInTheMiddleOfEnteringANumber = _userIsInTheMiddleOfEnteringANumber;
@synthesize brain = _brain;
-(CalculatorBrain *)brian
{
if (! _brain) _brain = [[CalculatorBrain alloc] init];
return _brain;
}
哈哈哈,雞蛋在我的臉上。 爲什麼這個編譯和工作很好?爲什麼沒有警告? – 2012-01-05 21:09:17