1

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

/Users/....mm:136:173:警告:方法调度中缺少哨兵 [-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++ 文件。

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

4

2 回答 2

1

从编译器输出中,我相信您没有nil正确地将 a 放在可变参数方法调用的末尾。

于 2014-05-07T13:51:09.977 回答
1

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

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

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

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

于 2014-05-07T13:51:56.520 回答