【发布时间】:2017-10-30 22:49:55
【问题描述】:
我在Class A 的目标-C 中有 2 个类:
我定义:
@property (nonatomic, readwrite) BOOL fortextview;
并像这样使用它:
if (![_support_long_messages boolValue]) {
[self showAlert];
_fortextview = false;
} else {
_fortextview = true ;
}
所以class B 取class A 的值并像这样使用它:
@property (nonatomic, strong) MessagingKeyServerResponse *messaginKeyRespo;
MessagingKeyServerResponse 是class A。
在我的class B我定义了if语句
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSUInteger newLength = [textView.text length] + [text length] - range.length;
if (_messaginKeyRespo.fortextview){
return (newLength > MESSAGE_MAX_LENGTH) ? NO : YES;
} else {
return (newLength > 160) ? NO : YES;
}
}
问题是值不通过,任何帮助不胜感激-
【问题讨论】:
-
在 shouldChangeTextInRange 中是 Messaginkeyrespo nil 吗?
-
是的,它显示为零。
-
你需要给 A 类引用 Messaginkeyrespo,否则它将为零。你是如何从 A 班转到 B 班的?
-
然后在你的
class B中点赞,` @property (assign, nonatomic) MessagingKeyServerResponse *Messaginkeyrespo` 并在class A中初始化class B时点赞,ClassB *classB = [[ClassB alloc] init] 然后是下一行,classB。 Messaginkeyrespo = 自我 -
我没有在 A 类中添加引用
标签: objective-c class boolean