gpt4 book ai didi

ios - 格式指定类型 ‘int’ 但参数的类型为 ‘float’

转载 作者:行者123 更新时间:2023-11-28 19:40:24 25 4
gpt4 key购买 nike

如果我将常量定义为整数,它如何被识别为 float ?

我在 Xcode 6.1.1 下构建并运行了下面的代码,没有出现任何问题。这个问题是在我升级到 Xcode 7.2 (7C68) 和 El Capitan 之后才出现的。

iOSCircleView.m

int const SECTORS_80 = 80;


@implementation iOSCircleView

- (void)ViewSettings_OverView {

sectors = SECTORS_80;

NSLog(@"sectors %i", sectors);
}

当我运行它时,NSLog 报告了一个警告

Format specifies type ‘int’ but the argument has type ‘float’

控制台显示

2016-01-07 10:05:00.210 AutoDrawUI[1298:555384] sectors 855670784

如果我将 NSLog 命令更改为

    NSLog(@"sectors %f”, sectors);

重新运行代码,没有警告但控制台显示

2016-01-07 10:38:01.547 AutoDrawUI[1330:632806] sectors 80.000000

这似乎是一个错误。但也许我错过了什么

这里是原始代码

int   const SECTORS_80          = 80;

@implementation iOSCircleView

// Initialisation

// frame a view for drawing

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {

// Initialization code
totalCircles = [[NSMutableArray alloc] init];
centre = [[NSMutableArray alloc] init];
ring = [[NSMutableArray alloc] init];

// Set background color
self.backgroundColor = [UIColor grayColor];

}
return self;
}

// initialise single target view (7 others are commented out)

- (void)drawRect:(CGRect)rect {

[self ViewSettings_OverView]; // 1. "launch view" ??

}

正在运行(注意:问题发生在它到达这里之前)

    // run

- (void)autoDrawUI {
[self drawCircle];
}

这是完整的类(class)(未经编辑)

     // initialise display settings

- (void)ViewSettings_OverView {

viewState = 0;
// number of dots on perimeter
sectors = SECTORS_80; // WARNING HERE
limit = sectors;;

if (sectors <= 0) { // WARNING HERE

show = FALSE; // disable
} else
show = TRUE; // enable perimeter dots

// radius of large circle perimeter
uberRadius = UBERRADIUS_52;

// radius of dots on large circle perimeter
dotRadius = DOTRADIUS_4;

dotsFilled = TRUE; // outline
oneColour = TRUE; // every colour
alternateDots = TRUE; // alternately filled and coloured

oddEvenState = 1; // PlayView

ringDot = RINGDOT_HIDE; //_SHOW104
centreDotFilled = FALSE; // fill or outline

centreDot = CENTREDOT_HIDE; //CENTREDOT_SHOW26;
centreDotFilled = TRUE; // fill or outline

NSLog(@"View %i", viewState);
NSLog(@"sectors %i", sectors); // WARNING HERE
NSLog(@"show %i", show);
[self centreReference];

}

这是 .h 文件

    #import <UIKit/UIKit.h>

@interface iOSCircleView : UIView
{
NSMutableArray *totalCircles;
NSMutableArray *sectorDots;

// following Stackoverflow 08/02/2015 ?
NSMutableArray *centre; // 1 of 5 (Global View), centre (Wait View), even bell icon (Play View)
NSMutableArray *ring; // odd bell icon (Play View)
// TO DO
NSMutableArray *sectorDotsCyan; // 16 moons surround 1 of 5 buttons on Global View
NSMutableArray *sectorDotsRed; // 16 moons 2
NSMutableArray *sectorDotsYellow; // 16 moons 3
NSMutableArray *sectorDotsMagenta; // 16 moons 4
NSMutableArray *sectorDotsGreen; // 16 moons 5

int dotCount, // working
colourIndex, // working
toggleIndex, // working
imageIndex,
limit, // working
selectedZone, // working
selectedPhone,
selectedState,
state,
viewState, // working
ringDotFilled,
centreDotFilled, // working
dotsFilled, // working
labelShown,
oneColour, // working
alternateDots,
i, // working
show; // working

BOOL shakeTap, // PlayView
oddEvenPhone, // LocalView
oddEvenState; // working

float uberX, // working
uberY, // working
uberRadius, // working
uberAngle, // working
labelX,
labelY,
dotRadius, // working
sectors, // working
x, // working
y, // working
ringDot, // working
centreDot, // working
textOffset, // working
startAngle,
dotAngle,
endAngle,
angle;

CGPoint dotPosition;
CGRect boxBoundary;
CGContextRef context;
}

@property(nonatomic,retain) UIColor* fillColor;
@property(nonatomic,retain) UIColor* circle;
@property(nonatomic,retain) UIImage* anImage;


- (void)drawCircle;
- (void)drawRosette;

@end

...问题立即变得显而易见。我将扇区声明为 float 的,不知何故我以前是如何逃脱的。我的大脑还在度假!

最佳答案

您的问题与 SECTORS_80 无关。这都是关于 sectors 变量的,因为这是您正在记录的变量。您没有指定它是如何声明的,但显然错误表明您将其声明为 float

改变:

float sectors;

到:

int sectors;

或更改格式以使用 %f。无论哪种方式都会消除错误。但只有一个才是真正合适的,具体取决于您的需要。

关于ios - 格式指定类型 ‘int’ 但参数的类型为 ‘float’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34648357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com