我正在教自己通过斯坦福大学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