【问题标题】:Format specifies type "unsigned long" but the argument has type "int"格式指定类型“unsigned long”,但参数类型为“int”
【发布时间】:2015-02-03 05:18:31
【问题描述】:

格式指定类型为“unsigned long”,但参数的类型为“int”

我在 XCode 中收到此错误,无论我输入什么格式说明符,或者如果我更改为 NSInteger、NSUInteger、long 或 int,仍然会出现错误!?我该如何解决这个问题?

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

{

我有这些行,第 2 行是 @"%lu",(row % max) 处的错误

NSUInteger max = (NSInteger)[self.calendar maximumRangeOfUnit:NSCalendarUnitHour].length;
[lblDate setText:[NSString stringWithFormat:@"%lu",(row % max)]]; 
lblDate.textAlignment = NSTextAlignmentRight;

感谢您的帮助!

【问题讨论】:

    标签: ios objective-c format-specifiers


    【解决方案1】:

    对于NSInteger,您应该使用%td%tu 作为NSUInteger

    查看此链接了解更多详情https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

    【讨论】:

    • 好的,看起来 xcode 对 %td 很满意,尽管它一直在建议别的东西。谢谢!
    • Xcode 建议了特定于架构的修复,其中 %t 用正确的东西代替了当前架构 - 很高兴它起作用了
    【解决方案2】:

    将您的代码更改为以下内容:

    NSUInteger max = (NSInteger)[self.calendar maximumRangeOfUnit:NSCalendarUnitHour].length;
    [lblDate setText:[NSString stringWithFormat:@"%d",(int)(row % max)]]; 
    lblDate.textAlignment = NSTextAlignmentRight;
    

    【讨论】:

      【解决方案3】:

      使用与 NSUInteger 类型匹配的格式说明符,如 %tu,或将 (row % max) 的结果转换为 int。

      【讨论】:

        【解决方案4】:

        好的,看起来 xcode 对 %td 很满意,尽管它一直在暗示其他东西。谢谢 !

        【讨论】:

          猜你喜欢
          • 2014-01-28
          • 2017-09-04
          • 2015-06-10
          • 1970-01-01
          • 1970-01-01
          • 2014-04-23
          • 1970-01-01
          • 2021-01-11
          • 1970-01-01
          相关资源
          最近更新 更多