如何将Bool值从一个类传递到另一个类

时间:2017-05-30 12:42:59

标签: objective-c class boolean

我在Class A中的目标-C中有2个类:  我定义了:

@property (nonatomic, readwrite) BOOL fortextview;

并使用它:

   if (![_support_long_messages boolValue]) {
        [self showAlert];
        _fortextview = false;
    } else {
        _fortextview = true ;
    }

因此class Bclass 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;
     }
}

问题是价值没有通过,任何帮助升值 -

1 个答案:

答案 0 :(得分:0)

创建全局变量然后它可以工作。

它解决了我的问题。 BOOL character_support;