【问题标题】:IPhone SDK removal of NSLog causes NSArray to be undeclared !iPhone SDK 移除 NSLog 会导致 NSArray 未声明!
【发布时间】:2010-02-07 08:59:45
【问题描述】:

我有一个正在运行的应用程序,我将要分发并整理其中的 NSLog 语句。当我从“case”语句中删除 NSLog 时,在“case”语句中声明的 NSArray 错误为 AND 未声明之前的预期表达式。有人知道为什么会这样吗?这发生在我现在删除 NSLog 的应用程序中的所有 case 语句中。 示例代码部分如下所示:

switch (chosenScene)
{
    case 0:
        //NSLog(@"group1"); // the following NSArray errors with "expected expression.." AND "..group1Secondsarray undeclared"
        NSArray *group1SecondsArray = [NSArray arrayWithObjects: @"Dummy",@"1/15",@"1/30",@"1/30",@"1/60",@"1/125",@"1/250",nil];
        NSArray *group1FStopArray = [NSArray arrayWithObjects: @"Dummy",@"2.8",@"2.8",@"4",@"5.6",@"5.6",@"5.6",nil];
        NSString *group1SecondsText = [group1SecondsArray objectAtIndex:slider.value];
        calculatedSeconds.text = group1SecondsText;
        NSString *group1FStopText = [group1FStopArray objectAtIndex:slider.value];
        calculatedFStop.text = group1FStopText;
        [group1SecondsText release];
        [group1FStopText release];          
        break;

【问题讨论】:

    标签: iphone sdk nsarray


    【解决方案1】:

    我不知道正式的解释,但如果你做的不是简单的赋值或在 case 语句中返回一个值,那么你需要把它放在括号内。

    case 0:
    {
        NSArray* myArray=[NSArray arrayWithObjects:ob1, obj2,nil];
        ...
    }
    

    【讨论】:

    • Maxwell Segal -- 如果这是答案,请点击它旁边的复选标记,以便系统知道该问题已得到解答,因此 Eyal Redler 将因此获得荣誉。
    【解决方案2】:

    您不必释放group1SecondsTextgroup1FStopText,它们的保留计数为 1,因为它们在数组中,如果释放它们它们将变为无效,并且当释放数组时它会中断.

    当您使用 objectAtIndex: 访问 NSArray 中的对象时,它不会增加保留计数,它只是从数组中返回对象。

    【讨论】:

    • 感谢您对我的问题的及时答复。干杯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多