Format指定类型"unsigned long"但参数的类型为"int"

Kre*_*erg 3 objective-c format-specifiers ios

Format指定类型"unsigned long"但参数的类型为"int"

我在XCode中得到此错误,无论我放入什么格式说明符,或者如果我更改为NSInteger,NSUInteger,long或int,仍然会出错!?我怎样才能解决这个问题?

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
Run Code Online (Sandbox Code Playgroud)

{

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

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

感谢帮助 !

Sas*_*ats 9

因为NSInteger你应该使用%td%tuNSUInteger

有关详细信息,请参阅此链接https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

  • Xcode建议特定于体系结构的修复,其中`%t`替代当前体系结构的正确事物 - 很高兴它有效 (2认同)