ios - 按值传递的结构参数包含未初始化的数据

标签 ios objective-c xcode cocos2d-iphone

我在下面的代码部分收到以下“按值传递的结构参数包含未初始化的数据”:

for ( int i = 0; i < 48; i++ )
{

    CGPoint posLevel;
    LevelButton* pBtn;
    if ( i >= 0 && i < 24 )
    {
        int nXX = (i % 4 + 1);

        if ( i < [pBtnArray count] )
        {
            posLevel = ccp( (spMask.position.x - mySize.width / 2) + mySize.width / 5 * nXX, 
                           mySize.height - mySize.height / 7 * (i / 4 + 1));
            pBtn = [pBtnArray objectAtIndex:i];
            if ( pBtn != nil )
            {
                [pBtn move:posLevel];
            }

        }

    }

使用 xcode 添加的箭头,是否有帮助??

enter image description here

删除注释掉的代码后,这里的代码就不多了,所以我不明白 XCode 抛出的问题是什么。

如能帮助消除此错误,我们将不胜感激!

最佳答案

你截图中的代码是这样的

CGRect posLevel;
if (mySize.height < 568) {
    posLevel = ...;
}
if (mySize.height >= 568) {
    posLevel = ...;
}
[pBtn move:posLevel];

而且似乎静态分析器无法识别第一个 或者在任何情况下都会执行第二个 if block 。 蓝色箭头表示两个 if block 都执行的流程, 在这种情况下,posLevel 将是未定义的。

您可以使用 if-else 来解决这个问题:

CGRect posLevel;
if (mySize.height < 568) {
    posLevel = ...;
} else {
    posLevel = ...;
}
[pBtn move:posLevel];

关于ios - 按值传递的结构参数包含未初始化的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19669097/

相关文章:

ios - Objective-C 索引数组

iOS动态加载自定义字体错误收集保留

ios - 为什么我的按钮在横向模式下不显示?

iphone - AVAudioPlayer 改变声音节奏?

ios - 更改 iPad 的自动布局约束

ios - 当我在 TableView 单元格的 uiimageview 上添加长按手势时。Uiimageview 未显示正确的图像

iphone - 我应该怎么做才能使我的应用程序适应 iOS 5.0 以保持与 iOS 4 的兼容性

xcode - 重新排序框架的经验法则?

javascript - "aps environment"如何解决呢?

iphone - 如果在 addSubView 之后调用,UIButton 不会移动