【问题标题】:How to bind enumerate variable changed in objc?如何绑定在objc中更改的枚举变量?
【发布时间】:2018-12-20 07:39:58
【问题描述】:

我已准备好将我的项目迁移到 RAC,但是当我想绑定属性的更改时出现错误。

#import <UIKit/UIKit.h>
@interface XBXMLoginTextField : UIView
@property (nonatomic, assign) UIKeyboardType keyboardType;
@end

在 .m 文件中:

- (instancetype)init {
    if (self = [super init]) {

        [RACObserve(self, keyboardType) subscribeNext:^(UIKeyboardType x) {

        }];
    }
    return self;
}

有一个错误-> 不兼容的块指针类型将“void (^)(UIKeyboardType)”发送到“void (^_Nonnull)(id _Nullable __strong)”类型的参数

我的代码有什么问题?

【问题讨论】:

    标签: ios objective-c iphone reactive-cocoa


    【解决方案1】:

    RACObserve 返回一个信号,该信号将其整数值作为装箱的NSNumber * 触发,因此您需要使用它的integerValue

    [RACObserve(self, keyboardType) subscribeNext:^(NSNumber *keyboardType) {
        NSLog(@"%ld", (long)keyboardType.integerValue);
    
        // Or any other user of keyboardType.integerValue, such as:
        if (keyboardType.integerValue == UIKeyboardTypeURL) {
            // Do stuff.
        }
    }];
    

    【讨论】:

    • 太棒了!你帮了我很多。非常感谢你!祝您在即将到来的圣诞节过得愉快!
    猜你喜欢
    • 2023-04-05
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多