【问题标题】:Objective-C++ Error: Expected unqualified-idObjective-C++ 错误:预期的不合格 ID
【发布时间】:2017-03-21 23:50:25
【问题描述】:

最近我检查了我的一个旧应用程序,当我停止使用它时,它仍然运行良好。但是现在每次我定义UIImage *new 时都会收到错误Expected unqualified-id

方法如下:

- (void)endTorsoWithUIImageView:(UIImageView *)flipper andError:(NSError *)clothingManagerError {
    currActiveCol.torsoCurrCol = (direction == 1)? currActiveCol.torsoCurrCol + 1 : currActiveCol.torsoCurrCol - 1;
    [clothingManager notifyAboutMovementInSection:ECOSTorso inDirection:(direction == 1)? ECCDNext : ECCDPrevious];

    if (direction == 1) {
        if (currActiveCol.torsoCurrCol + 2 < [[clothingManager.sectionSetSizes objectAtIndex:0] intValue]) {
            flipper = [[sectionMatrix objectAtIndex:0] objectAtIndex:(currActiveCol.torsoCurrCol + 2) % 4];
            [flipper setHidden:YES];
            [flipper setCenter:(direction == 1)?   CGPointMake(self.view.bounds.size.width + self.outfitView.frame.size.width, flipper.center.y) : CGPointMake(0 - self.outfitView.frame.size.width, flipper.center.y)];
            [flipper setHidden:NO];

            ECChangeDirection dir = (direction == 1)? ECCDNext : ECCDPrevious;
            UIImage *new = [clothingManager updateAfterChangeInDirection:dir forSection:ECOSTorso withError:&clothingManagerError];
            if (new != NULL) {
                [flipper setImage:new];
                [flipper setFrame:CGRectMake(flipper.frame.origin.x, flipper.frame.origin.y, flipper.frame.size.width, [self ratifierForImage:new])];
                [self centerImageView:flipper forFocus:ASTorso takingLoctionIntoAccount:NO forLocation:0];
                [[imageAssetCollection objectAtIndex:0] replaceObjectAtIndex:(currActiveCol.torsoCurrCol + 2) % 4
                                                              withObject:new];
            } else {
                // TODO: Report error to google analytics
            }
        }
    } else if (direction == -1) {
        if (currActiveCol.torsoCurrCol - 2 >= 0) {
            flipper = [[sectionMatrix objectAtIndex:0] objectAtIndex:(currActiveCol.torsoCurrCol - 2) % 4];
            [flipper setHidden:YES];
            [flipper setCenter:(direction == 1)? CGPointMake(self.view.bounds.size.width + self.outfitView.frame.size.width, flipper.center.y) : CGPointMake(0 - self.outfitView.frame.size.width, flipper.center.y)];
            [flipper setHidden:NO];

            UIImage *new = (UIImage *)[clothingManager updateAfterChangeInDirection:(direction == 1)? ECCDNext : ECCDPrevious                                                           forSection:ECOSTorso                                                                         withError:&clothingManagerError];
            if (new != NULL) {
                [flipper setImage:new];
                [flipper setFrame:CGRectMake(flipper.frame.origin.x, flipper.frame.origin.y, flipper.frame.size.width, [self ratifierForImage:new])];
                [self centerImageView:flipper forFocus:ASTorso takingLoctionIntoAccount:NO forLocation:0];
                [[imageAssetCollection objectAtIndex:0] replaceObjectAtIndex:(currActiveCol.torsoCurrCol + 2) % 4
                                                              withObject:new];
            } else {
                // TODO: Report error to google analytics
            }
        }
    }
}

方法定义如下- (UIImage * _Nullable)updateAfterChangeInDirection:(ECChangeDirection)direction forSection:(ECOutfitSection)ecos withError:(NSError * _Nullable * _Nullable)error;。该方法本身没有问题返回特定图像或如果不存在图像则返回 NULL。

我真的很迷茫,非常感谢任何提示。

【问题讨论】:

  • 不要使用“new”作为变量名开头。并用 nil 而不是 NULL 来检查你的 UIImage 。 developer.apple.com/library/content/documentation/Cocoa/…
  • 就是这样!非常感谢!如果您将其添加为答案,我会将其标记为答案????再次感谢您!
  • 我很高兴它有帮助:)

标签: c++ ios objective-c uiimage objective-c++


【解决方案1】:

不要使用new 作为变量名开头。并使用nil 而非NULL 进行UIImage 检查。

Look here for info on naming properties

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    相关资源
    最近更新 更多