V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
walkingway
V2EX  ›  iDev

新人请教斯坦福2011年秋季iPhone课程第二节课碰到的一个问题

  •  
  •   walkingway · 2012-04-21 15:58:12 +08:00 · 2900 次点击
    这是一个创建于 4394 天前的主题,其中的信息可能已经有所发展或是发生改变。
    斯坦福老头的课看到第二节,编写计算器时碰到一个问题没想明白,是关于BOOL类型的 userIsInTheMiddleOfEnteringANumber变量 来判断用户是否是输入的第一个数字,这是个自定义的私有方法,用@property和@synthesize来合成存取器方法。紧接着下面的if (self.userIsInTheMiddleOfEnteringANumber) 就获取了userIsInTheMiddleOfEnteringANumber中的值来做判断

    请问:这个获取的userIsInTheMiddleOfEnteringANumber值从哪里来的,还是BOOL类型的默认了@property和@synthesize之后初始值就是NO?

    如下:

    #import "CalculatorViewController.h"

    @interface CalculatorViewController ()
    @property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
    @end

    @implementation CalculatorViewController

    @synthesize display = _display;
    @synthesize userIsInTheMiddleOfEnteringANumber = _userIsInTheMiddleOfEnteringANumber;


    - (IBAction)digipressd:(UIButton *)sender
    {
    NSString *digit = [sender currentTitle];

    if (self.userIsInTheMiddleOfEnteringANumber) {
    self.display.text = [self.display.text stringByAppendingString:digit];
    }
    else {
    self.display.text = digit;
    self.userIsInTheMiddleOfEnteringANumber = YES;
    }
    }
    2 条回复    1970-01-01 08:00:00 +08:00
    laihj
        1
    laihj  
       2012-04-21 16:04:20 +08:00
    BOOL的初始值是NO
    walkingway
        2
    walkingway  
    OP
       2012-04-21 16:07:02 +08:00
    @laihj 多谢,这样就理顺了!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2203 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:12 · PVG 18:12 · LAX 03:12 · JFK 06:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.