我想创建一个 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/