ios - 尽管参数列表中存在 nil,但在方法调度中缺少哨兵

标签 ios objective-c cocoa-touch compiler-warnings sentinel

我想创建一个 UIActionSheet 但我总是收到关于“缺少哨兵”的警告:

/Users/....mm:136:173: warning: missing sentinel in method dispatch [-Wsentinel]

UIActionSheet* adsl_action_sheet = [[[UIActionSheet alloc] initWithTitle:nil 
                                                                delegate:(id<UIActionSheetDelegate>)self 
                                                       cancelButtonTitle:[dsd_string_localizer ms_get_localized_system_string:@"Cancel"] 
                                                  destructiveButtonTitle:nil 
                                                       otherButtonTitles:[dsd_string_localizer ms_get_localized_system_string:@"Logoff"], [dsd_string_localizer ms_get_localized_system_string:@"Disconnect"], nil] autorelease];

我真的看不出有什么不对...也许我只是瞎了。

包含此代码的文件是一个 Objective-C++ 文件。

我还注意到它在每个需要这种哨兵的地方都显示了这些“哨兵警告”。

最佳答案

您需要将最终的“哨兵”nil 转换为正确的类型,使用:

... , (NSString *)nil] autorelease];
//    ^^^^^^^^^^^^

但是,我不确定为什么编译器需要这个转换。

相信在使用 -Wstrict-null-sentinel 编译时这是必要的(等待 OP 的确认)。

关于ios - 尽管参数列表中存在 nil,但在方法调度中缺少哨兵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23519134/

相关文章:

iphone - 使用 mkmap 加载 map 时显示标题

ios - 本地通知未到达

ios - Swift 3.0 使用 write(toFile : atomically:) 写入二进制图像数据

ios - 如何在不使用 Firebase 控制台的情况下向 iOS 设备发送 Firebase 云消息传递通知?

ios - JSQMessagesViewController - 发送带有附加图像文件的文本消息

iphone - 如何在构建时测试 UIViewController?

ios - Swift:没有标签栏的屏幕截图

ios - Objective-c:未声明的标识符 applicationDidEnterBackground

ios - 在 UITableView 中的部分索引标题之间添加填充(或增加高度)

ios - 延迟动画UIImageView