- (id) firstResponder: (UIView *) navView {
for (id aview in [self allSubviews:navView]) {
if ([aview isKindOfClass:[UITextField class]] && [(UITextField *)aview isFirstResponder]) {
return (UITextField *)aview;
}
else if ([aview isKindOfClass:[UITextView class]] && [(UITextView *)aview isFirstResponder]) {
return (UITextView *)aview;
}
}
return NO;
}
收到错误:从iOS 8中的常量布尔表达式初始化类型'id'的指针为null。
答案 0 :(得分:6)
变化:
return NO;
为:
return nil;
(NO
是一个布尔文字,编译器抱怨它被转换为类型id
以便返回。)
答案 1 :(得分:0)
如何更改实现如下...
在此,您无需担心NO
,nil
,null
等,即使编译器不会警告id
或integer
- (id) firstResponder: (UIView *) navView {
UIView *view = nil;
for (id aview in [self allSubviews:navView]) {
if ([aview isKindOfClass:[UITextField class]] && [(UITextField *)aview isFirstResponder]) {
view = (UITextField *)aview;
}
else if ([aview isKindOfClass:[UITextView class]] && [(UITextView *)aview isFirstResponder]) {
view = (UITextView *)aview;
}
}
return view;
}