小编app*_*eDE的帖子

单身和KVO的问题

在我的应用程序中,我创建了我的自定义类,我正在使用KVO观察其属性之一,因此如果其值发生更改,它会立即显示在firstview控制器对象(标签或...)中

示例代码

myCustomClass.h

@interface myCustomClass : NSObject {
    NSString * text;
}
@property (nonatomic, retain) NSString * text;
- (void)changetext;
Run Code Online (Sandbox Code Playgroud)

myCustomClass.m

@implementation myCustomClass

@synthesize text;
static myCustomClass * _sharedInstance;

- (id)init
{
    if ((self = [super init])) {
        text = @ "";
    }
    return self;
}

+ (myCustomClass *)sharedInstance
{
    if (!_sharedInstance) {
        _sharedInstance = [[myCustomClass alloc] init];
    }

    return _sharedInstance;
}
- (void)changetext {
    text = @ "changed";
}
Run Code Online (Sandbox Code Playgroud)

firstViewController.h

@interface FirstViewController:UIViewController {

    IBOutlet UILabel * label;
}
@property …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios4

2
推荐指数
2
解决办法
1138
查看次数

标签 统计

ios4 ×1

iphone ×1

objective-c ×1