Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将分段控制值存储为变量。如何修复这些警告?_Ios_Objective C - Fatal编程技术网

Ios 将分段控制值存储为变量。如何修复这些警告?

Ios 将分段控制值存储为变量。如何修复这些警告?,ios,objective-c,Ios,Objective C,我有以下代码,但我收到警告“不兼容的整数到指针转换从int分配给NSInteger(又称int)。qaviable是一个int变量,我只尝试存储选择为该变量的任何值。尽管有警告,这是否仍有效 - (IBAction)segmentcontrollerA { if (controlA.selectedSegmentIndex == 0) { qAVariable = 0; } if (controlA.selectedSegmentIndex == 1)

我有以下代码,但我收到警告“不兼容的整数到指针转换从int分配给
NSInteger
(又称int)。
qaviable
是一个int变量,我只尝试存储选择为该变量的任何值。尽管有警告,这是否仍有效

- (IBAction)segmentcontrollerA {

    if (controlA.selectedSegmentIndex == 0) {
        qAVariable = 0;
    }
    if (controlA.selectedSegmentIndex == 1) {
        qAVariable = 1;
    }
    if (controlA.selectedSegmentIndex == 2) {
        qAVariable = 2;
    }
    if (controlA.selectedSegmentIndex == 3) {
        qAVariable = 3;
    }
    if (controlA.selectedSegmentIndex == 4) {
        qAVariable = 4;
    }
}
在32位体系结构中编译时,NSinteger是32位int(因此您的基本
int
),而在为新的64位arch编译时,NSinteger是64位整数(a
long
)。这就解释了警告。您可以简单地将NSinteger强制转换为int以避免警告:

qAVariable = (int)controlA.selectedSegmentIndex;

您正在为
qaviable
指定一个整数值。您的警告表明您没有将其声明为平面整数数据类型,而是将其声明为指针,即
NSNumber*
int*

,您还可以将属性更改为:

@property (nonatomic, assign) NSInteger qAVariable;

警告显示在哪一行?如果使用switch语句,代码看起来会更干净!因此警告显示在第2-5条if语句中。第一条值为0的语句没有显示任何警告。他的代码没有使用此选项,整数也不会发出“int-to-pointer”转换“警告。如果我理解正确的话,他正试图直接将selectedSegmentIndex(正如原因所指示的)分配给他的var,并且为了避免警告,他切换到了那堆If语句。没有理由这么做。不,他的代码没有这样做,即使这样做了,也不会导致这个错误。事实上,这一转换不会改变任何事情,因为selectedSegmentIndex是一个NSInteger,它最多只能引发一个有符号/无符号警告。他确实提到了这个警告:“不兼容的整数到指针转换”。我将它声明为NSInteger又名NSInteger*Qaviable;应该是什么?“NSInteger”不是“NSInteger*”。它应该是“NSInteger”,通常只是“int”的typedefNInteger*'是指向“NSInteger”的指针,完全不同。啊,明白了!好了,这修正了警告。非常感谢:D