- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的模型类:
标题:
@interface RTSecurityModel : NSObject
{
NSString *code;
}
@property NSString *code;
@end
实现:
@implementation RTSecurityModel
@synthesize code;
@end
然后我就有了我的应用程序代理:
标题:
@interface RTAppDelegate : NSObject <NSApplicationDelegate>
{
RTSecurityModel *security;
}
@property (assign) IBOutlet NSWindow *window;
@property RTSecurityModel *security;
@end
实现:
@implementation RTAppDelegate
@synthesize security;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
security = [[RTSecurityModel alloc] init];
security.code = @"test";
}
然后在我的 MainMenu.xib 中创建一个标签,并在绑定(bind)检查器中设置“绑定(bind)到:应用程序委托(delegate)”和“模型 key 路径:security.code”。
但是当我开始我的应用程序时没有任何显示。
我尝试了很多方法来绑定(bind)这个变量,但没有人成功。
请帮助我不要讨厌 XCode 和 Cocoa!
以下是如何通过编辑文本字段设置属性和标签值的示例
但是有没有一种方法可以在不编辑文本字段的情况下编辑标签?或者根本没有文本字段?
UPD2:
您不得创建另一个对象实例
security = [[RTSecurityModel alloc] init]; // Kill this
非常感谢维克托·列克星敦
最佳答案
不要使用 security.code
作为模型路径,而是使用 code
。在绑定(bind)选项卡的值部分使用类 RTSecurityModel
而不是 AppDelegate。
Here是一个演示项目。
请勿绑定(bind)文本字段单元格
,而是使用文本字段
。
如果您用文本填充Null Placeholder
,您可以检查值是否为空,它会显示该文本吗?然后在绑定(bind)值时将其设置为空。
要在 Interface Builder 中查看您的 RTSecurityModel
,您必须让它知道您的类,它不会查找它。
添加一个对象,然后将其自定义类设置为RTSecurityModel
。然后您可以选择该对象并将引用 socket 设置为App Delegate中的属性。分配现在将直接反射(reflect)在标签中。
<小时/>
我可以想出两种无需 Interface Builder 以编程方式解决此问题的方法:
// add an observer for the value on the object that has the method below implemented
[self addObserver: self forKeyPath: @"security.code" options: NSKeyValueObservingOptionNew context: NULL];
// method will be called when the observer has 'seen' a value change
-(void) observeValueForKeyPath: (NSString *)keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context {
label.text = ...
}
为 code
使用自定义 setter(@synthesize
仍将为您创建 getter)
- (void)setCode:(NSString *)aString {
label.text = aString;
}
关于objective-c - Xcode OSX,将 NSString 绑定(bind)到 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25230510/
使用 WSDL2ObjC 我得到了很多类,它们是 NSString 的子类。我发现初始化这些类的任何对象的 NSString 值很麻烦。 假设我的类(class)是这样的: @interface mC
当调用 +[NSURL URLWithString:] 时,我有两个构建 URL 的选项: [[@"http://example.com" stringByAppendingPathComponent
我需要删除字符串末尾的空格。我怎样才能做到这一点?示例:如果字符串是 "Hello " 它必须变成 "Hello" 最佳答案 摘自这里的答案:https://stackoverflow.com/a/5
NSString *test = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 如何将此字符串转换为字节? 最佳答案 NSData *bytes = [test dataUsingEn
我对 NSString 变量有疑问。 .h 文件 NSString *strDeleteFilePath; @property (nonatomic,retain) NSString*
我对这个功能有疑问: - (instancetype)initWithCenter:(CLLocationCoordinate2D)center
如果我有方法 - (void) myMethod:(NSString *)string { [Object anothermethodWithString:string]; } 我打电话 [O
ios 中初始化字符串变量的两种方式有什么区别(,adv/disadv)? NSString *var = @"value" 和 NSString *var =[ [NSString alloc] i
我认为这个问题已经足够清楚了,但仍然 - 有什么区别: NSString *string = @"Hello world!"; 和 NSString *string = [[NSString allo
我正在尝试将 NSString 转换为单个字符。当我写 [[NSLocale] currentLocale] objectForKey:NSLocaleDecimalSeparator] 时,我得到
我有指示制作一个前缀方法,该方法在每个位置采用两个字符串,其中 mask = 0 并且第一个字符串 = 第二个字符串,直到不满足这些条件为止,即您的前缀 NSString。 我做了尝试,但由于某种原因
我有 3 个 NSString 和 1 个带值的 NSArray,我尝试将所有字符串转换为一个: string01 = [string01 stringByAppendingString:[numbe
我有一个包含以下文本的 NSString: You can now download "file.png" from "http://www.example.com/RANDOM.png" 如何使用该
我有一个完整的 URL,比方说 http://www.mywebsite.com//Folder /Detals /Final Image /La Image Logo.jpg 在这个NSString
在某些情况下,我可能有一个包含多个单词的 NSString,其中一些是重复的。我想要做的是采用如下所示的字符串: One Two Three Three Three Two Two Two One O
所以我有一个 NSString,让我们说:NSString *mainString = @"My Name is Andrew (I like computers)";我想从 mainString 中
这是我的职责。首先 println 将正确的散列打印到控制台,但在下一行程序崩溃。你能帮助我吗? func sha256(string: NSString) -> NSString { var
我刚刚看到一行由同事编写的代码,我以前从未在 Obj-C 中见过它。它看起来形式很糟糕,我想更改它,但它似乎有效(应用程序按预期工作),我什至不知道将其更改为什么。 NSString **string
我花了很长时间寻找一种获取 nsstring 对象的匹配计数的方法。但我找不到。如何获取 String_one 和 String_Two 的匹配计数?我需要你的帮助.. NSString *Strin
在我看来,我正在处理的代码应该是这样写的: if (!instructions) { instructions = [[UITextView alloc] init]; ins
我是一名优秀的程序员,十分优秀!