Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从预期返回非null值的方法返回的Nil_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 从预期返回非null值的方法返回的Nil

Ios 从预期返回非null值的方法返回的Nil,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我正在实现uikeyinport、uiteImportRaits、和uiteImport,因此我需要实现: - (NSArray *)selectionRectsForRange:(UITextRange *)range { return nil; } 然而,在分析我的项目时,我得到:“nil从一个预期返回非空值的方法返回” 正确的方法是什么?我应该执行中止吗?不要返回nil。如果你没有 UITextSelectionRects要返回,请返回一个空数组。实际上,如果您查看头源,该方法会

我正在实现
uikeyinport
uiteImportRaits
、和
uiteImport
,因此我需要实现:

- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
    return nil;
}
然而,在分析我的项目时,我得到:“nil从一个预期返回非空值的方法返回”


正确的方法是什么?我应该执行中止吗?

不要返回
nil
。如果你没有
UITextSelectionRects要返回,请返回一个空数组。

实际上,如果您查看头源,该方法会附加
NS\u假设\u非空\u开始
标记。因此,简而言之,
selectionRectsForRange
成为非空返回方法

//
//  UITextInput.h
//  UIKit
//
//  Copyright (c) 2009-2017 Apple Inc. All rights reserved.
//

#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UITextInputTraits.h>
#import <UIKit/UIResponder.h>

...

NS_ASSUME_NONNULL_BEGIN  // <--- HERE!
..
- (CGRect)firstRectForRange:(UITextRange *)range;
- (CGRect)caretRectForPosition:(UITextPosition *)position;
- (NSArray *)selectionRectsForRange:(UITextRange *)range NS_AVAILABLE_IOS(6_0); 

“我应该终止程序吗”?这是什么意思?拔掉你电脑的插头?@matt我换了它,我的意思是说,我应该做一个中止()。@SerPounce请检查我的答案。除了初始化一个长度为1的NSArray并返回它之外,还有更干净的方法吗?不是长度为1。空的。不要紧,我刚刚做了:return[[NSArray alloc]init]<代码>返回@[]也许?
- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
    return @[];
}